RDMA/rxe: Add dma-buf support
Subsystems (3)
v3 cover RDMA/rxe: Add dma-buf support
This patch series add a dma-buf support for rxe driver.
A dma-buf based memory registering has beed introduced to use the memory region that lack of associated page structures (e.g. device memory and CMA managed memory) [1]. However, to use the dma-buf based memory, each rdma device drivers require add some implementation. The rxe driver has not support yet.
[1] https://www.spinics.net/lists/linux-rdma/msg98592.html
To enable to use the dma-buf memory in rxe rdma device, add some changes and implementation in this patch series.
This series consists of two patches. The first patch changes the IB core to support for rdma drivers that has not dma device. The secound patch adds the dma-buf support to rxe driver.
Related user space RDMA library changes are provided as a separate patch.
v3:
* Rebase to the latest linux-rdma 'for-next' branch (5.15.0-rc6+)
* Fix to use dma-buf-map helpers
v2: https://www.spinics.net/lists/linux-rdma/msg105928.html
* Rebase to the latest linux-rdma 'for-next' branch (5.15.0-rc1+)
* Instead of using a dummy dma_device to attach dma-buf, just store dma-buf to use software RDMA driver
* Use dma-buf vmap() interface
* Check to pass tests of rdma-core
v1: https://www.spinics.net/lists/linux-rdma/msg105376.html
* The initial patch set
* Use ib_device as dma_device.
* Use dma-buf dynamic attach interface
* Add dma-buf support to rxe device
Shunsuke Mie (2):
RDMA/umem: Change for rdma devices has not dma device RDMA/rxe: Add dma-buf support
drivers/infiniband/core/umem_dmabuf.c | 20 ++++- drivers/infiniband/sw/rxe/rxe_loc.h | 2 + drivers/infiniband/sw/rxe/rxe_mr.c | 113 ++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_verbs.c | 34 ++++++++ include/rdma/ib_umem.h | 1 + 5 files changed, 166 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
RFC PATCH v3 1/2 RDMA/umem: Change for rdma devices has not dma device
Current implementation requires a dma device for RDMA driver to use dma-buf memory space as RDMA buffer. However, software RDMA drivers has not dma device and copy RDMA data using CPU instead of hardware.
This patch changes to be hold a dma-buf on struct ib_umem_dmabuf. This allows the software RDMA driver to map dma-buf memory for CPU memory accessing.
--- drivers/infiniband/core/umem_dmabuf.c | 20 ++++++++++++++++---- include/rdma/ib_umem.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-)
drivers/infiniband/core/umem_dmabuf.c +16 -4
@@ -117,9 +117,6 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device,if (check_add_overflow (offset, (unsigned long )size, &end))return ret; -if (unlikely (!ops || !ops->move_notify)) -return ret; - dmabuf =dma_buf_get (fd);if (IS_ERR (dmabuf))return ERR_CAST (dmabuf);
@@ -133,6 +130,8 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device, goto out_release_dmabuf; } + umem_dmabuf->dmabuf = dmabuf; + umem = &umem_dmabuf->umem; umem->ibdev = device; umem->length = size;
@@ -143,6 +142,13 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device,if (!ib_umem_num_pages (umem)) goto out_free_umem; +/* Software RDMA drivers has not dma device. Just get dmabuf from fd */ +if (!device->dma_device) + goto done; + +if (unlikely (!ops || !ops->move_notify)) + goto out_free_umem; + umem_dmabuf->attach = dma_buf_dynamic_attach( dmabuf, device->dma_device,
@@ -152,6 +158,7 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device, ret =ERR_CAST (umem_dmabuf->attach); goto out_free_umem; } +done:return umem_dmabuf; out_free_umem:
@@ -165,13 +172,18 @@ EXPORT_SYMBOL(ib_umem_dmabuf_get);void ib_umem_dmabuf_release (struct ib_umem_dmabuf *umem_dmabuf) { -struct dma_buf *dmabuf = umem_dmabuf->attach->dmabuf; +struct dma_buf *dmabuf = umem_dmabuf->dmabuf; + +if (!umem_dmabuf->attach) + goto free_dmabuf;dma_resv_lock (dmabuf->resv,NULL );ib_umem_dmabuf_unmap_pages (umem_dmabuf);dma_resv_unlock (dmabuf->resv);dma_buf_detach (dmabuf, umem_dmabuf->attach); + +free_dmabuf:dma_buf_put (dmabuf);kfree (umem_dmabuf); }
include/rdma/ib_umem.h +1 -0
@@ -32,6 +32,7 @@ struct ib_umem {struct ib_umem_dmabuf {struct ib_umem umem;struct dma_buf_attachment *attach; +struct dma_buf *dmabuf;struct sg_table *sgt;struct scatterlist *first_sg;struct scatterlist *last_sg;
Signature · 1 line
2.17.1
RFC PATCH v3 2/2 RDMA/rxe: Add dma-buf support
In reply to Shunsuke MieImplement a ib device operation ‘reg_user_mr_dmabuf’. Generate a rxe_map from the memory space linked the passed dma-buf.
--- drivers/infiniband/sw/rxe/rxe_loc.h | 2 + drivers/infiniband/sw/rxe/rxe_mr.c | 113 ++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_verbs.c | 34 ++++++++ 3 files changed, 149 insertions(+)
drivers/infiniband/sw/rxe/rxe_loc.h +2 -0
@@ -75,6 +75,8 @@ u8 rxe_get_next_key(u32 last_key);void rxe_mr_init_dma (struct rxe_pd *pd,int access,struct rxe_mr *mr);int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr); +int rxe_mr_dmabuf_init_user (struct rxe_pd *pd,int fd,u64 start,u64 length, +u64 iova,int access,struct rxe_mr *mr);int rxe_mr_init_fast (struct rxe_pd *pd,int max_pages,struct rxe_mr *mr);int rxe_mr_copy (struct rxe_mr *mr,u64 iova,void *addr,int length,enum rxe_mr_copy_dir dir);
drivers/infiniband/sw/rxe/rxe_mr.c +113 -0
131 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_verbs.c +34 -0
@@ -940,6 +940,39 @@ static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd,return ERR_PTR (err); } +static struct ib_mr *rxe_reg_user_mr_dmabuf (struct ib_pd *ibpd,u64 start, +u64 length,u64 iova,int fd, +int access,struct ib_udata *udata) +{ +int err; +struct rxe_dev *rxe =to_rdev (ibpd->device); +struct rxe_pd *pd =to_rpd (ibpd); +struct rxe_mr *mr; + + mr =rxe_alloc (&rxe->mr_pool); +if (!mr) { + err = -ENOMEM ; + goto err2; + } + +rxe_add_index (mr); + +rxe_add_ref (pd); + + err =rxe_mr_dmabuf_init_user (pd, fd, start, length, iova, access, mr); +if (err) + goto err3; + +return &mr->ibmr; + +err3: +rxe_drop_ref (pd); +rxe_drop_index (mr); +rxe_drop_ref (mr); +err2: +return ERR_PTR (err); +} +static struct ib_mr *rxe_alloc_mr (struct ib_pd *ibpd,enum ib_mr_type mr_type,u32 max_num_sg) {
@@ -1105,6 +1138,7 @@ static const struct ib_device_ops rxe_dev_ops = { .query_qp = rxe_query_qp, .query_srq = rxe_query_srq, .reg_user_mr = rxe_reg_user_mr, + .reg_user_mr_dmabuf = rxe_reg_user_mr_dmabuf, .req_notify_cq = rxe_req_notify_cq, .resize_cq = rxe_resize_cq,
Signature · 1 line
2.17.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 Shunsuke,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on rdma/for-next]
[also build test WARNING on v5.15-rc7 next-20211029]
[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/Shunsuke-Mie/RDMA-rxe-Add-dma-buf-support/20211029-150351 base: https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next config: riscv-randconfig-r042-20211029 (attached as .config) compiler: riscv32-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/132b40bb2550f801c5e94fcde19f28b29b0852e2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shunsuke-Mie/RDMA-rxe-Add-dma-buf-support/20211029-150351 git checkout 132b40bb2550f801c5e94fcde19f28b29b0852e2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/infiniband/sw/rxe/rxe_mr.c: In function 'rxe_map_dmabuf_mr':
>> drivers/infiniband/sw/rxe/rxe_mr.c:256:23: warning: variable 'vaddr_end' set but not used [-Wunused-but-set-variable]
256 | void *vaddr, *vaddr_end;
| ^~~~~~~~~
In file included from include/linux/dma-buf.h:16,
from drivers/infiniband/sw/rxe/rxe_mr.c:7:
drivers/infiniband/sw/rxe/rxe_mr.c: In function 'rxe_unmap_dmabuf_mr':
>> drivers/infiniband/sw/rxe/rxe_mr.c:305:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
305 | (void *)mr->cur_map_set->map[0]->buf->addr);
| ^
include/linux/dma-buf-map.h:129:27: note: in definition of macro 'DMA_BUF_MAP_INIT_VADDR'
129 | .vaddr = (vaddr_), \
| ^~~~~~vim +/vaddr_end +256 drivers/infiniband/sw/rxe/rxe_mr.c
249
250 static int rxe_map_dmabuf_mr(struct rxe_mr *mr,
251 struct ib_umem_dmabuf *umem_dmabuf)
252 {
253 struct rxe_map_set *set;
254 struct rxe_phys_buf *buf = NULL;
255 struct rxe_map **map;
> 256 void *vaddr, *vaddr_end;
257 int num_buf = 0;
258 int err;
259 size_t remain;
260 struct dma_buf_map dmabuf_map;
261
262 err = dma_buf_vmap(umem_dmabuf->dmabuf, &dmabuf_map);
263 if (err || dmabuf_map.is_iomem)
264 goto err_out;
265
266 set = mr->cur_map_set;
267 set->page_shift = PAGE_SHIFT;
268 set->page_mask = PAGE_SIZE - 1;
269
270 map = set->map;
271 buf = map[0]->buf;
272
273 vaddr = dmabuf_map.vaddr;
274 vaddr_end = vaddr + umem_dmabuf->dmabuf->size;
275 remain = umem_dmabuf->dmabuf->size;
276
277 for (; remain; vaddr += PAGE_SIZE) {
278 if (num_buf >= RXE_BUF_PER_MAP) {
279 map++;
280 buf = map[0]->buf;
281 num_buf = 0;
282 }
283
284 buf->addr = (uintptr_t)vaddr;
285 if (remain >= PAGE_SIZE)
286 buf->size = PAGE_SIZE;
287 else
288 buf->size = remain;
289 remain -= buf->size;
290
291 num_buf++;
292 buf++;
293 }
294
295 return 0;
296
297 err_out:
298 return err;
299 }
300
301 static void rxe_unmap_dmabuf_mr(struct rxe_mr *mr)
302 {
303 struct ib_umem_dmabuf *umem_dmabuf = to_ib_umem_dmabuf(mr->umem);
304 struct dma_buf_map map = DMA_BUF_MAP_INIT_VADDR(
> 305 (void *)mr->cur_map_set->map[0]->buf->addr); 306
307 dma_buf_vunmap(umem_dmabuf->dmabuf, &map);
308 }
309
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
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 Shunsuke,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on rdma/for-next]
[also build test ERROR on v5.15 next-20211111]
[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/Shunsuke-Mie/RDMA-rxe-Add-dma-buf-support/20211029-150351 base: https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next config: s390-allyesconfig (attached as .config) compiler: s390-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/132b40bb2550f801c5e94fcde19f28b29b0852e2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shunsuke-Mie/RDMA-rxe-Add-dma-buf-support/20211029-150351 git checkout 132b40bb2550f801c5e94fcde19f28b29b0852e2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/infiniband/sw/rxe/rxe_mr.c: In function 'rxe_map_dmabuf_mr':
>> drivers/infiniband/sw/rxe/rxe_mr.c:256:23: error: variable 'vaddr_end' set but not used [-Werror=unused-but-set-variable]
256 | void *vaddr, *vaddr_end;
| ^~~~~~~~~cc1: all warnings being treated as errors
vim +/vaddr_end +256 drivers/infiniband/sw/rxe/rxe_mr.c
249
250 static int rxe_map_dmabuf_mr(struct rxe_mr *mr,
251 struct ib_umem_dmabuf *umem_dmabuf)
252 {
253 struct rxe_map_set *set;
254 struct rxe_phys_buf *buf = NULL;
255 struct rxe_map **map;
> 256 void *vaddr, *vaddr_end;
257 int num_buf = 0;
258 int err;
259 size_t remain;
260 struct dma_buf_map dmabuf_map;
261
262 err = dma_buf_vmap(umem_dmabuf->dmabuf, &dmabuf_map);
263 if (err || dmabuf_map.is_iomem)
264 goto err_out;
265
266 set = mr->cur_map_set;
267 set->page_shift = PAGE_SHIFT;
268 set->page_mask = PAGE_SIZE - 1;
269
270 map = set->map;
271 buf = map[0]->buf;
272
273 vaddr = dmabuf_map.vaddr;
274 vaddr_end = vaddr + umem_dmabuf->dmabuf->size;
275 remain = umem_dmabuf->dmabuf->size;
276
277 for (; remain; vaddr += PAGE_SIZE) {
278 if (num_buf >= RXE_BUF_PER_MAP) {
279 map++;
280 buf = map[0]->buf;
281 num_buf = 0;
282 }
283
284 buf->addr = (uintptr_t)vaddr;
285 if (remain >= PAGE_SIZE)
286 buf->size = PAGE_SIZE;
287 else
288 buf->size = remain;
289 remain -= buf->size;
290
291 num_buf++;
292 buf++;
293 }
294
295 return 0;
296
297 err_out:
298 return err;
299 }
300
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org