linux-stable/include/rdma
Mike Marciniszyn b7b24a7ffc RDMA/core: Fix umem iterator when PAGE_SIZE is greater then HCA pgsz
[ Upstream commit 4fbc3a52cd ]

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: 10c75ccb54 ("RDMA/umem: Prevent small pages from being returned by ib_umem_find_best_pgsz()")
Link: https://lore.kernel.org/r/20231129202143.1434-2-shiraz.saleem@intel.com
Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-12-13 18:36:40 +01:00
..
ib.h
ib_addr.h
ib_cache.h
ib_cm.h
ib_hdrs.h
ib_mad.h
ib_marshall.h
ib_pack.h
ib_pma.h
ib_sa.h
ib_smi.h
ib_sysfs.h
ib_umem.h
ib_umem_odp.h
ib_verbs.h
iba.h
ibta_vol1_c12.h
iw_cm.h
iw_portmap.h
lag.h
mr_pool.h
opa_addr.h
opa_port_info.h
opa_smi.h
opa_vnic.h
rdma_cm.h
rdma_cm_ib.h
rdma_counter.h
rdma_netlink.h
rdma_vt.h
rdmavt_cq.h
rdmavt_mr.h
rdmavt_qp.h
restrack.h
rw.h
signature.h
tid_rdma_defs.h
uverbs_ioctl.h
uverbs_named_ioctl.h
uverbs_std_types.h
uverbs_types.h