Skip to contentSkip to conversation

RDMA/rxe: Remove redundant page presence check

PATCH Superseded Daisuke Matsuda 2 participants 4 messages Jun 8, 2025 – Jun 11, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA/rxe: Remove redundant page presence check

hmm_pfn_to_page() does not return NULL. ib_umem_odp_map_dma_and_lock() should return an error in case the target pages cannot be mapped until timeout, so these checks can safely be removed.

---
 drivers/infiniband/sw/rxe/rxe_odp.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/infiniband/sw/rxe/rxe_odp.c +1 -12
index dbc5a5600eb7..02841346e30c 100644
@@ -203,8 +203,6 @@ static int __rxe_odp_mr_copy(struct rxe_mr *mr, u64 iova, void *addr,
 
 		page = hmm_pfn_to_page(umem_odp->map.pfn_list[idx]);
 		user_va = kmap_local_page(page);
-		if (!user_va)
-			return -EFAULT;
 
 		src = (dir == RXE_TO_MR_OBJ) ? addr : user_va;
 		dest = (dir == RXE_TO_MR_OBJ) ? user_va : addr;
@@ -286,8 +284,6 @@ static enum resp_states rxe_odp_do_atomic_op(struct rxe_mr *mr, u64 iova,
 	idx = rxe_odp_iova_to_index(umem_odp, iova);
 	page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
 	page = hmm_pfn_to_page(umem_odp->map.pfn_list[idx]);
-	if (!page)
-		return RESPST_ERR_RKEY_VIOLATION;
 
 	if (unlikely(page_offset & 0x7)) {
 		rxe_dbg_mr(mr, "iova not aligned\n");
@@ -352,10 +348,6 @@ int rxe_odp_flush_pmem_iova(struct rxe_mr *mr, u64 iova,
 		page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
 
 		page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-		if (!page) {
-			mutex_unlock(&umem_odp->umem_mutex);
-			return -EFAULT;
-		}
 
 		bytes = min_t(unsigned int, length,
 			      mr_page_size(mr) - page_offset);
@@ -398,10 +390,7 @@ enum resp_states rxe_odp_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value)
 	page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
 	index = rxe_odp_iova_to_index(umem_odp, iova);
 	page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-	if (!page) {
-		mutex_unlock(&umem_odp->umem_mutex);
-		return RESPST_ERR_RKEY_VIOLATION;
-	}
+
 	/* See IBA A19.4.2 */
 	if (unlikely(page_offset & 0x7)) {
 		mutex_unlock(&umem_odp->umem_mutex);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 23 lines · Daisuke Matsuda

hmm_pfn_to_page() does not return NULL. ib_umem_odp_map_dma_and_lock() should return an error in case the target pages cannot be mapped until timeout, so these checks can safely be removed.

---
  drivers/infiniband/sw/rxe/rxe_odp.c | 13 +------------
  1 file changed, 1 insertion(+), 12 deletions(-)
drivers/infiniband/sw/rxe/rxe_odp.c +0 -2
index dbc5a5600eb7..02841346e30c 100644
@@ -203,8 +203,6 @@ static int __rxe_odp_mr_copy(struct rxe_mr *mr, u64 iova, void *addr,
 
  		page = hmm_pfn_to_page(umem_odp->map.pfn_list[idx]);
  		user_va = kmap_local_page(page);
-		if (!user_va)
-			return -EFAULT;
 
  		src = (dir == RXE_TO_MR_OBJ) ? addr : user_va;
  		dest = (dir == RXE_TO_MR_OBJ) ? user_va : addr;

drivers/infiniband/sw/rxe/rxe_odp.c static enum resp_states rxe_odp_do_atomic_op(struct rxe_mr *mr, u64 iova, · line 286

Quoted 3 lines
drivers/infiniband/sw/rxe/rxe_odp.c +0 -0
@@ -286,8 +284,6 @@ static enum resp_states rxe_odp_do_atomic_op(struct rxe_mr *mr, u64 iova,
  	idx = rxe_odp_iova_to_index(umem_odp, iova);
  	page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
  	page = hmm_pfn_to_page(umem_odp->map.pfn_list[idx]);

The function hmm_pfn_to_page will finally be "(mem_map + ((pfn) - ARCH_PFN_OFFSET))"

The procedure is as below:

hmm_pfn_to_page -- > pfn_to_page -- > __pfn_to_page -- > (mem_map + ((pfn) - ARCH_PFN_OFFSET))

Thus, I am fine with it.

drivers/infiniband/sw/rxe/rxe_odp.c static enum resp_states rxe_odp_do_atomic_op(struct rxe_mr *mr, u64 iova, · line 288

Quoted 4 lines
drivers/infiniband/sw/rxe/rxe_odp.c +0 -2
-	if (!page)
-		return RESPST_ERR_RKEY_VIOLATION;
 
  	if (unlikely(page_offset & 0x7)) {

Normally page_offset error handler should be after this line "page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);"

Why is this error handler after hmm_pfn_to_page?

Quoted 13 lines
drivers/infiniband/sw/rxe/rxe_odp.c +0 -4
  		rxe_dbg_mr(mr, "iova not aligned\n");
@@ -352,10 +348,6 @@ int rxe_odp_flush_pmem_iova(struct rxe_mr *mr, u64 iova,
  		page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
 
  		page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-		if (!page) {
-			mutex_unlock(&umem_odp->umem_mutex);
-			return -EFAULT;
-		}
 
  		bytes = min_t(unsigned int, length,
  			      mr_page_size(mr) - page_offset);

drivers/infiniband/sw/rxe/rxe_odp.c enum resp_states rxe_odp_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value) · line 395

Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_odp.c +1 -4
@@ -398,10 +390,7 @@ enum resp_states rxe_odp_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value)
  	page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
  	index = rxe_odp_iova_to_index(umem_odp, iova);
  	page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-	if (!page) {
-		mutex_unlock(&umem_odp->umem_mutex);
-		return RESPST_ERR_RKEY_VIOLATION;
-	}
+
  	/* See IBA A19.4.2 */
  	if (unlikely(page_offset & 0x7)) {

Ditto, page_offset error handler is not after the line "page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);" ?

Thanks
Yanjun.Zhu

Quoted 1 line
drivers/infiniband/sw/rxe/rxe_odp.c +0 -0
  		mutex_unlock(&umem_odp->umem_mutex);
Reviewed-by
#2 lore raw
Quoted 61 lines · Zhu Yanjun
Quoted 22 lines · Daisuke Matsuda

hmm_pfn_to_page() does not return NULL. ib_umem_odp_map_dma_and_lock() should return an error in case the target pages cannot be mapped until timeout, so these checks can safely be removed.

---
  drivers/infiniband/sw/rxe/rxe_odp.c | 13 +------------

  1 file changed, 1 insertion(+), 12 deletions(-)
drivers/infiniband/sw/rxe/rxe_odp.c +0 -2
index dbc5a5600eb7..02841346e30c 100644
@@ -203,8 +203,6 @@ static int __rxe_odp_mr_copy(struct rxe_mr *mr, 
 u64 iova, void *addr,
           page = hmm_pfn_to_page(umem_odp->map.pfn_list[idx]);
           user_va = kmap_local_page(page);
-        if (!user_va)
-            return -EFAULT;
           src = (dir == RXE_TO_MR_OBJ) ? addr : user_va;
           dest = (dir == RXE_TO_MR_OBJ) ? user_va : addr;

drivers/infiniband/sw/rxe/rxe_odp.c static enum resp_states · line 287

Quoted 4 lines
drivers/infiniband/sw/rxe/rxe_odp.c +0 -0
@@ -286,8 +284,6 @@ static enum resp_states 
 rxe_odp_do_atomic_op(struct rxe_mr *mr, u64 iova,
       idx = rxe_odp_iova_to_index(umem_odp, iova);
       page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
       page = hmm_pfn_to_page(umem_odp->map.pfn_list[idx]);

The function hmm_pfn_to_page will finally be "(mem_map + ((pfn) - ARCH_PFN_OFFSET))"

The procedure is as below:

hmm_pfn_to_page -- > pfn_to_page -- > __pfn_to_page -- > (mem_map + ((pfn) - ARCH_PFN_OFFSET))

Thus, I am fine with it.

drivers/infiniband/sw/rxe/rxe_odp.c static enum resp_states rxe_odp_do_atomic_op(struct rxe_mr *mr, u64 iova, · line 288

Quoted 3 lines
drivers/infiniband/sw/rxe/rxe_odp.c +0 -2
-    if (!page)
-        return RESPST_ERR_RKEY_VIOLATION;
       if (unlikely(page_offset & 0x7)) {

Normally page_offset error handler should be after this line "page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);"

Why is this error handler after hmm_pfn_to_page?

Quoted 17 lines
drivers/infiniband/sw/rxe/rxe_odp.c +0 -5
           rxe_dbg_mr(mr, "iova not aligned\n");
@@ -352,10 +348,6 @@ int rxe_odp_flush_pmem_iova(struct rxe_mr *mr, 
 u64 iova,
           page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
           page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-        if (!page) {
-            mutex_unlock(&umem_odp->umem_mutex);
-            return -EFAULT;
-        }
           bytes = min_t(unsigned int, length,
                     mr_page_size(mr) - page_offset);
@@ -398,10 +390,7 @@ enum resp_states rxe_odp_do_atomic_write(struct 
 rxe_mr *mr, u64 iova, u64 value)
       page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
       index = rxe_odp_iova_to_index(umem_odp, iova);
       page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-    if (!page) {
Quoted 8 lines

drivers/infiniband/sw/rxe/rxe_odp.c enum resp_states rxe_odp_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value) · line 395

Quoted 6 lines
drivers/infiniband/sw/rxe/rxe_odp.c +1 -3
-        mutex_unlock(&umem_odp->umem_mutex);
-        return RESPST_ERR_RKEY_VIOLATION;
-    }
+
       /* See IBA A19.4.2 */
       if (unlikely(page_offset & 0x7)) {

Ditto, page_offset error handler is not after the line "page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);" ?

Other than that, I am fine with this commit.
Thanks,

Zhu Yanjun

Quoted 6 lines

Thanks
Yanjun.Zhu

Quoted 1 line

          mutex_unlock(&umem_odp->umem_mutex);

Signature · 2 lines
Best Regards,
Yanjun.Zhu
#3 lore raw
In reply to Zhu Yanjun
Quoted 7 lines · Zhu Yanjun
Quoted 6 lines · Daisuke Matsuda

hmm_pfn_to_page() does not return NULL. ib_umem_odp_map_dma_and_lock() should return an error in case the target pages cannot be mapped until timeout, so these checks can safely be removed.

---

<...>

Quoted 24 lines
Quoted 4 lines

-    if (!page)
-        return RESPST_ERR_RKEY_VIOLATION;
      if (unlikely(page_offset & 0x7)) {

Normally page_offset error handler should be after this line "page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);"

Why is this error handler after hmm_pfn_to_page?

Quoted 15 lines

          rxe_dbg_mr(mr, "iova not aligned\n");

drivers/infiniband/sw/rxe/rxe_odp.c +0 -5
@@ -352,10 +348,6 @@ int rxe_odp_flush_pmem_iova(struct rxe_mr *mr, u64 iova,
           page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
           page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-        if (!page) {
-            mutex_unlock(&umem_odp->umem_mutex);
-            return -EFAULT;
-        }
           bytes = min_t(unsigned int, length,
                     mr_page_size(mr) - page_offset);
@@ -398,10 +390,7 @@ enum resp_states rxe_odp_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value)
       page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);
       index = rxe_odp_iova_to_index(umem_odp, iova);
       page = hmm_pfn_to_page(umem_odp->map.pfn_list[index]);
-    if (!page) {
Quoted 8 lines

drivers/infiniband/sw/rxe/rxe_odp.c enum resp_states rxe_odp_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value) · line 395

Quoted 6 lines
drivers/infiniband/sw/rxe/rxe_odp.c +1 -3
-        mutex_unlock(&umem_odp->umem_mutex);
-        return RESPST_ERR_RKEY_VIOLATION;
-    }
+
       /* See IBA A19.4.2 */
       if (unlikely(page_offset & 0x7)) {

Ditto, page_offset error handler is not after the line "page_offset = rxe_odp_iova_to_page_offset(umem_odp, iova);" ?

That is a sensible question.
I will submit v3 patch to move the error checks.

Thank you,
Daisuke