From: Shunsuke Mie <mie@igel.co.jp>
To: Zhu Yanjun <zyjzyj2000@gmail.com>
Cc: "Shunsuke Mie" <mie@igel.co.jp>,
"Christian König" <christian.koenig@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Daniel Vetter" <daniel.vetter@ffwll.ch>,
"Doug Ledford" <dledford@redhat.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Jianxin Xiong" <jianxin.xiong@intel.com>,
"Leon Romanovsky" <leon@kernel.org>,
linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
dhobsong@igel.co.jp, taki@igel.co.jp, etom@igel.co.jp
Subject: [RFC PATCH 2/3] RDMA/rxe: Extract a mapping process into a function
Date: Wed, 8 Sep 2021 15:16:10 +0900 [thread overview]
Message-ID: <20210908061611.69823-3-mie@igel.co.jp> (raw)
In-Reply-To: <20210908061611.69823-1-mie@igel.co.jp>
Functionization of the process to generate the memory map. The function
generates maps from scatterlists to a list of page aligned addresses.
Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
---
drivers/infiniband/sw/rxe/rxe_mr.c | 89 ++++++++++++++++++------------
1 file changed, 54 insertions(+), 35 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index be4bcb420fab..8b08705ed62a 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -103,15 +103,59 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)
mr->type = RXE_MR_TYPE_DMA;
}
+/* generate a rxe memory map data structure from ib_umem */
+static int rxe_mr_gen_map(struct rxe_mr *mr, struct ib_umem *umem)
+{
+ int err;
+ int num_buf;
+ struct rxe_map **map;
+ struct rxe_phys_buf *buf = NULL;
+ struct sg_page_iter sg_iter;
+ void *vaddr;
+
+ num_buf = 0;
+ map = mr->map;
+ if (mr->length > 0) {
+ buf = map[0]->buf;
+
+ for_each_sg_page(umem->sg_head.sgl, &sg_iter, umem->nmap, 0) {
+ if (num_buf >= RXE_BUF_PER_MAP) {
+ map++;
+ buf = map[0]->buf;
+ num_buf = 0;
+ }
+
+ vaddr = page_address(sg_page_iter_page(&sg_iter));
+ if (!vaddr) {
+ pr_warn("%s: Unable to get virtual address", __func__);
+ err = -ENOMEM;
+ goto err1;
+ }
+
+ buf->addr = (uintptr_t)vaddr;
+ buf->size = PAGE_SIZE;
+ num_buf++;
+ buf++;
+ }
+ }
+
+ mr->umem = umem;
+ mr->offset = ib_umem_offset(umem);
+ mr->state = RXE_MR_STATE_VALID;
+ mr->type = RXE_MR_TYPE_MR;
+
+ return 0;
+
+err1:
+ ib_umem_release(umem);
+ return err;
+}
+
int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,
int access, struct rxe_mr *mr)
{
- struct rxe_map **map;
- struct rxe_phys_buf *buf = NULL;
struct ib_umem *umem;
- struct sg_page_iter sg_iter;
- int num_buf;
- void *vaddr;
+ int num_buf;
int err;
int i;
@@ -138,43 +182,18 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,
mr->page_shift = PAGE_SHIFT;
mr->page_mask = PAGE_SIZE - 1;
- num_buf = 0;
- map = mr->map;
- if (length > 0) {
- buf = map[0]->buf;
-
- for_each_sg_page(umem->sg_head.sgl, &sg_iter, umem->nmap, 0) {
- if (num_buf >= RXE_BUF_PER_MAP) {
- map++;
- buf = map[0]->buf;
- num_buf = 0;
- }
-
- vaddr = page_address(sg_page_iter_page(&sg_iter));
- if (!vaddr) {
- pr_warn("%s: Unable to get virtual address\n",
- __func__);
- err = -ENOMEM;
- goto err_cleanup_map;
- }
-
- buf->addr = (uintptr_t)vaddr;
- buf->size = PAGE_SIZE;
- num_buf++;
- buf++;
+ mr->length = length;
- }
+ err = rxe_mr_gen_map(mr, umem);
+ if (err) {
+ pr_warn("%s: Failed to map pages", __func__);
+ goto err_cleanup_map;
}
mr->ibmr.pd = &pd->ibpd;
- mr->umem = umem;
mr->access = access;
- mr->length = length;
mr->iova = iova;
mr->va = start;
- mr->offset = ib_umem_offset(umem);
- mr->state = RXE_MR_STATE_VALID;
- mr->type = RXE_MR_TYPE_MR;
return 0;
--
2.17.1
next prev parent reply other threads:[~2021-09-08 6:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-08 6:16 [RFC PATCH 0/3] RDMA/rxe: Add dma-buf support Shunsuke Mie
2021-09-08 6:16 ` [RFC PATCH 1/3] RDMA/umem: Change for rdma devices has not dma device Shunsuke Mie
2021-09-08 6:26 ` Christoph Hellwig
2021-09-08 7:01 ` Shunsuke Mie
2021-09-08 7:19 ` Christoph Hellwig
2021-09-08 8:41 ` Shunsuke Mie
2021-09-08 11:18 ` Jason Gunthorpe
2021-09-08 13:33 ` Christian König
2021-09-08 19:22 ` Daniel Vetter
2021-09-08 23:33 ` Jason Gunthorpe
2021-09-09 9:26 ` Daniel Vetter
2021-09-10 1:46 ` Shunsuke Mie
2021-09-13 19:22 ` Daniel Vetter
2021-09-14 7:11 ` Shunsuke Mie
2021-09-14 9:38 ` Daniel Vetter
2021-09-14 10:13 ` Shunsuke Mie
2021-09-08 6:16 ` Shunsuke Mie [this message]
2021-09-08 6:16 ` [RFC PATCH 3/3] RDMA/rxe: Support dma-buf as memory region Shunsuke Mie
2021-09-09 5:45 ` [RFC PATCH 0/3] RDMA/rxe: Add dma-buf support Zhu Yanjun
2021-09-10 2:00 ` Shunsuke Mie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210908061611.69823-3-mie@igel.co.jp \
--to=mie@igel.co.jp \
--cc=alexander.deucher@amd.com \
--cc=christian.koenig@amd.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dhobsong@igel.co.jp \
--cc=dledford@redhat.com \
--cc=etom@igel.co.jp \
--cc=jgg@ziepe.ca \
--cc=jianxin.xiong@intel.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=taki@igel.co.jp \
--cc=zyjzyj2000@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).