Skip to content

Commit 0a929e8

Browse files
mmarcinigregkh
authored andcommitted
RDMA/core: Fix umem iterator when PAGE_SIZE is greater then HCA pgsz
[ Upstream commit 4fbc3a5 ] 64k pages introduce the situation in this diagram when the HCA 4k page size is being used: +-------------------------------------------+ <--- 64k aligned VA | | | HCA 4k page | | | +-------------------------------------------+ | o | | | | o | | | | o | +-------------------------------------------+ | | | HCA 4k page | | | +-------------------------------------------+ <--- Live HCA page |OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO| <--- offset | | <--- VA | MR data | +-------------------------------------------+ | | | HCA 4k page | | | +-------------------------------------------+ | o | | | | o | | | | o | +-------------------------------------------+ | | | HCA 4k page | | | +-------------------------------------------+ The VA addresses are coming from rdma-core in this diagram can be arbitrary, but for 64k pages, the VA may be offset by some number of HCA 4k pages and followed by some number of HCA 4k pages. The current iterator doesn't account for either the preceding 4k pages or the following 4k pages. Fix the issue by extending the ib_block_iter to contain the number of DMA pages like comment [1] says and by using __sg_advance to start the iterator at the first live HCA page. The changes are contained in a parallel set of iterator start and next functions that are umem aware and specific to umem since there is one user of the rdma_for_each_block() without umem. These two fixes prevents the extra pages before and after the user MR data. Fix the preceding pages by using the __sq_advance field to start at the first 4k page containing MR data. Fix the following pages by saving the number of pgsz blocks in the iterator state and downcounting on each next. This fix allows for the elimination of the small page crutch noted in the Fixes. Fixes: 10c75cc ("RDMA/umem: Prevent small pages from being returned by ib_umem_find_best_pgsz()") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mike Marciniszyn <[email protected]> Signed-off-by: Shiraz Saleem <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ebcb4e1 commit 0a929e8

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

drivers/infiniband/core/umem.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
9696
return page_size;
9797
}
9898

99-
/* rdma_for_each_block() has a bug if the page size is smaller than the
100-
* page size used to build the umem. For now prevent smaller page sizes
101-
* from being returned.
102-
*/
103-
pgsz_bitmap &= GENMASK(BITS_PER_LONG - 1, PAGE_SHIFT);
104-
10599
/* The best result is the smallest page size that results in the minimum
106100
* number of required pages. Compute the largest page size that could
107101
* work based on VA address bits that don't change.

include/rdma/ib_umem.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter,
7878
{
7979
__rdma_block_iter_start(biter, umem->sgt_append.sgt.sgl,
8080
umem->sgt_append.sgt.nents, pgsz);
81+
biter->__sg_advance = ib_umem_offset(umem) & ~(pgsz - 1);
82+
biter->__sg_numblocks = ib_umem_num_dma_blocks(umem, pgsz);
83+
}
84+
85+
static inline bool __rdma_umem_block_iter_next(struct ib_block_iter *biter)
86+
{
87+
return __rdma_block_iter_next(biter) && biter->__sg_numblocks--;
8188
}
8289

8390
/**
@@ -93,7 +100,7 @@ static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter,
93100
*/
94101
#define rdma_umem_for_each_dma_block(umem, biter, pgsz) \
95102
for (__rdma_umem_block_iter_start(biter, umem, pgsz); \
96-
__rdma_block_iter_next(biter);)
103+
__rdma_umem_block_iter_next(biter);)
97104

98105
#ifdef CONFIG_INFINIBAND_USER_MEM
99106

include/rdma/ib_verbs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,7 @@ struct ib_block_iter {
28352835
/* internal states */
28362836
struct scatterlist *__sg; /* sg holding the current aligned block */
28372837
dma_addr_t __dma_addr; /* unaligned DMA address of this block */
2838+
size_t __sg_numblocks; /* ib_umem_num_dma_blocks() */
28382839
unsigned int __sg_nents; /* number of SG entries */
28392840
unsigned int __sg_advance; /* number of bytes to advance in sg in next step */
28402841
unsigned int __pg_bit; /* alignment of current block */

0 commit comments

Comments
 (0)