diff mbox series

[for-next,2/5] RDMA/rxe: use iova_to_vaddr to transform iova for rxe_mr_copy

Message ID 1668141030-2-3-git-send-email-lizhijian@fujitsu.com (mailing list archive)
State Changes Requested
Delegated to: Jason Gunthorpe
Headers show
Series iova_to_vaddr refactor | expand

Commit Message

Li Zhijian Nov. 11, 2022, 4:30 a.m. UTC
Make the code more friendly and readable by using iova_to_vaddr()

This commit also remove the err1 label in rxe_mr_copy().

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 drivers/infiniband/sw/rxe/rxe_mr.c | 46 +++++++++---------------------
 1 file changed, 13 insertions(+), 33 deletions(-)

Comments

Jason Gunthorpe Nov. 18, 2022, 4:41 p.m. UTC | #1
On Fri, Nov 11, 2022 at 04:30:27AM +0000, Li Zhijian wrote:
> Make the code more friendly and readable by using iova_to_vaddr()

But the point of this is to be faster because it knows pages are in a
linear list

As with my previous suggestion, just convert this to an xarray and
then it is a trivial and fast xas_for_each_range() returning struct
pages.

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index f6366a635b92..cf3ce8d293b3 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -289,13 +289,6 @@  void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length)
 int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
 		enum rxe_mr_copy_dir dir)
 {
-	int			err;
-	int			bytes;
-	u8			*va;
-	struct rxe_map		**map;
-	struct rxe_phys_buf	*buf;
-	int			m;
-	int			i;
 	size_t			offset;
 
 	if (length == 0)
@@ -315,49 +308,36 @@  int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
 
 	WARN_ON_ONCE(!mr->map);
 
-	err = mr_check_range(mr, iova, length);
-	if (err) {
-		err = -EFAULT;
-		goto err1;
-	}
-
-	lookup_iova(mr, iova, &m, &i, &offset);
-
-	map = mr->map + m;
-	buf	= map[0]->buf + i;
+	if (mr_check_range(mr, iova, length))
+		return -EFAULT;
 
+	offset = (iova - mr->ibmr.iova + mr->offset) & mr->page_mask;
 	while (length > 0) {
-		u8 *src, *dest;
-
-		va	= (u8 *)(uintptr_t)buf->addr + offset;
-		src = (dir == RXE_TO_MR_OBJ) ? addr : va;
-		dest = (dir == RXE_TO_MR_OBJ) ? va : addr;
+		u8 *src, *dest, *va;
+		int bytes;
 
 		bytes	= mr->ibmr.page_size - offset;
 
 		if (bytes > length)
 			bytes = length;
 
+		va = iova_to_vaddr(mr, iova, bytes);
+		if (!va)
+			return -EFAULT;
+
+		src = (dir == RXE_TO_MR_OBJ) ? addr : va;
+		dest = (dir == RXE_TO_MR_OBJ) ? va : addr;
+
 		memcpy(dest, src, bytes);
 
 		length	-= bytes;
 		addr	+= bytes;
+		iova += bytes;
 
 		offset	= 0;
-		buf++;
-		i++;
-
-		if (i == RXE_BUF_PER_MAP) {
-			i = 0;
-			map++;
-			buf = map[0]->buf;
-		}
 	}
 
 	return 0;
-
-err1:
-	return err;
 }
 
 /* copy data in or out of a wqe, i.e. sg list