This function should be used to get the offset from the first DMA block. The few places using this without a DMA iterator are calling it to work around the lack of setting sgl->offset when the umem is created. Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx> --- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +- drivers/infiniband/hw/qedr/verbs.c | 2 +- drivers/infiniband/sw/rdmavt/mr.c | 2 +- drivers/infiniband/sw/rxe/rxe_mr.c | 2 +- include/rdma/ib_umem.h | 9 ++++++--- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 49d6ddc37b6fde..c840115b8c0945 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -369,7 +369,7 @@ int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, } ret = sg_pcopy_to_buffer(umem->sg_head.sgl, umem->sg_nents, dst, length, - offset + ib_umem_offset(umem)); + offset + ib_umem_dma_offset(umem, PAGE_SIZE)); if (ret < 0) return ret; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index 1fb8da6d613674..f22532fbc364fe 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -870,7 +870,7 @@ struct ib_mr *ocrdma_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, goto umem_err; mr->hwmr.pbe_size = PAGE_SIZE; - mr->hwmr.fbo = ib_umem_offset(mr->umem); + mr->hwmr.fbo = ib_umem_dma_offset(mr->umem, PAGE_SIZE); mr->hwmr.va = usr_addr; mr->hwmr.len = len; mr->hwmr.remote_wr = (acc & IB_ACCESS_REMOTE_WRITE) ? 1 : 0; diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index 278b48443aedba..daac742e71044d 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -2878,7 +2878,7 @@ struct ib_mr *qedr_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, mr->hw_mr.pbl_two_level = mr->info.pbl_info.two_layered; mr->hw_mr.pbl_page_size_log = ilog2(mr->info.pbl_info.pbl_size); mr->hw_mr.page_size_log = PAGE_SHIFT; - mr->hw_mr.fbo = ib_umem_offset(mr->umem); + mr->hw_mr.fbo = ib_umem_dma_offset(mr->umem, PAGE_SIZE); mr->hw_mr.length = len; mr->hw_mr.vaddr = usr_addr; mr->hw_mr.zbva = false; diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c index 2f7c25fea44a9d..04f7dc0ce9e44d 100644 --- a/drivers/infiniband/sw/rdmavt/mr.c +++ b/drivers/infiniband/sw/rdmavt/mr.c @@ -404,7 +404,7 @@ struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, mr->mr.user_base = start; mr->mr.iova = virt_addr; mr->mr.length = length; - mr->mr.offset = ib_umem_offset(umem); + mr->mr.offset = ib_umem_dma_offset(umem, PAGE_SIZE); mr->mr.access_flags = mr_access_flags; mr->umem = umem; diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 708e2dff5eaa70..8f60dc9dee8658 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -196,7 +196,7 @@ int rxe_mem_init_user(struct rxe_pd *pd, u64 start, mem->length = length; mem->iova = iova; mem->va = start; - mem->offset = ib_umem_offset(umem); + mem->offset = ib_umem_dma_offset(umem, PAGE_SIZE); mem->state = RXE_MEM_STATE_VALID; mem->type = RXE_MEM_TYPE_MR; diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h index 4bac6e29f030c2..5e709b2c251644 100644 --- a/include/rdma/ib_umem.h +++ b/include/rdma/ib_umem.h @@ -27,10 +27,13 @@ struct ib_umem { unsigned int sg_nents; }; -/* Returns the offset of the umem start relative to the first page. */ -static inline int ib_umem_offset(struct ib_umem *umem) +/* + * Returns the offset of the umem start relative to the first DMA block returned + * by rdma_umem_for_each_dma_block(). + */ +static inline int ib_umem_dma_offset(struct ib_umem *umem, unsigned long pgsz) { - return umem->address & ~PAGE_MASK; + return umem->address & (pgsz - 1); } static inline size_t ib_umem_num_dma_blocks(struct ib_umem *umem, -- 2.28.0