[PATCH rdma-next] RDMA/umem: Use consistent DMA attributes when unmapping entries

Leon Romanovsky posted 1 patch 1 week, 5 days ago
drivers/infiniband/core/umem.c | 11 +++++------
include/rdma/ib_umem.h         |  1 +
2 files changed, 6 insertions(+), 6 deletions(-)
[PATCH rdma-next] RDMA/umem: Use consistent DMA attributes when unmapping entries
Posted by Leon Romanovsky 1 week, 5 days ago
From: Leon Romanovsky <leonro@nvidia.com>

The DMA API expects that mapping and unmapping use the same DMA
attributes. The RDMA umem code did not meet this requirement, so fix
the mismatch.

Fixes: f03d9fadfe13 ("RDMA/core: Add weak ordering dma attr to dma mapping")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/umem.c | 11 +++++------
 include/rdma/ib_umem.h         |  1 +
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 4eef7b76fe465..f5f187593ef17 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -55,7 +55,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
 
 	if (dirty)
 		ib_dma_unmap_sgtable_attrs(dev, &umem->sgt_append.sgt,
-					   DMA_BIDIRECTIONAL, 0);
+					   DMA_BIDIRECTIONAL, umem->dma_attrs);
 
 	for_each_sgtable_sg(&umem->sgt_append.sgt, sg, i) {
 		unpin_user_page_range_dirty_lock(sg_page(sg),
@@ -169,7 +169,6 @@ struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
 	unsigned long lock_limit;
 	unsigned long new_pinned;
 	unsigned long cur_base;
-	unsigned long dma_attr = 0;
 	struct mm_struct *mm;
 	unsigned long npages;
 	int pinned, ret;
@@ -202,6 +201,9 @@ struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
 	umem->iova = addr;
 	umem->writable   = ib_access_writable(access);
 	umem->owning_mm = mm = current->mm;
+	if (access & IB_ACCESS_RELAXED_ORDERING)
+		umem->dma_attrs |= DMA_ATTR_WEAK_ORDERING;
+
 	mmgrab(mm);
 
 	page_list = (struct page **) __get_free_page(GFP_KERNEL);
@@ -254,11 +256,8 @@ struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
 		}
 	}
 
-	if (access & IB_ACCESS_RELAXED_ORDERING)
-		dma_attr |= DMA_ATTR_WEAK_ORDERING;
-
 	ret = ib_dma_map_sgtable_attrs(device, &umem->sgt_append.sgt,
-				       DMA_BIDIRECTIONAL, dma_attr);
+				       DMA_BIDIRECTIONAL, umem->dma_attrs);
 	if (ret)
 		goto umem_release;
 	goto out;
diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h
index 38414281a686b..2ad52cc1d52bd 100644
--- a/include/rdma/ib_umem.h
+++ b/include/rdma/ib_umem.h
@@ -18,6 +18,7 @@ struct ib_umem {
 	u64 iova;
 	size_t			length;
 	unsigned long		address;
+	unsigned long		dma_attrs;
 	u32 writable : 1;
 	u32 is_odp : 1;
 	u32 is_dmabuf : 1;

---
base-commit: 1c3eaf5186228f0b20ccb776e86233f069475380
change-id: 20260323-umem-dma-attrs-8e2b80e09c4c

Best regards,
--  
Leon Romanovsky <leonro@nvidia.com>

Re: [PATCH rdma-next] RDMA/umem: Use consistent DMA attributes when unmapping entries
Posted by Leon Romanovsky 6 days, 2 hours ago
On Mon, 23 Mar 2026 22:10:18 +0200, Leon Romanovsky wrote:
> The DMA API expects that mapping and unmapping use the same DMA
> attributes. The RDMA umem code did not meet this requirement, so fix
> the mismatch.

Applied, thanks!

[1/1] RDMA/umem: Use consistent DMA attributes when unmapping entries
      (no commit info)

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>