RDMA/core: Fix best page size finding when it can cross SG entries
authorMichael Margolin <mrgolin@amazon.com>
Mon, 17 Feb 2025 14:16:23 +0000 (14:16 +0000)
committerLeon Romanovsky <leon@kernel.org>
Wed, 19 Feb 2025 12:17:39 +0000 (07:17 -0500)
commit486055f5e09df959ad4e3aa4ee75b5c91ddeec2e
treee79c3c2718cfe8ab60613a0286008d11f30170eb
parent0172be244ce367dd51d77b777244ea9c8de34a3a
RDMA/core: Fix best page size finding when it can cross SG entries

A single scatter-gather entry is limited by a 32 bits "length" field
that is practically 4GB - PAGE_SIZE. This means that even when the
memory is physically contiguous, we might need more than one entry to
represent it. Additionally when using dmabuf, the sg_table might be
originated outside the subsystem and optimized for other needs.

For instance an SGT of 16GB GPU continuous memory might look like this:
(a real life example)

dma_address 34401400000, length fffff000
dma_address 345013ff000, length fffff000
dma_address 346013fe000, length fffff000
dma_address 347013fd000, length fffff000
dma_address 348013fc000, length 4000

Since ib_umem_find_best_pgsz works within SG entries, in the above case
we will result with the worst possible 4KB page size.

Fix this by taking into consideration only the alignment of addresses of
real discontinuity points rather than treating SG entries as such, and
adjust the page iterator to correctly handle cross SG entry pages.

There is currently an assumption that drivers do not ask for pages
bigger than maximal DMA size supported by their devices.

Reviewed-by: Firas Jahjah <firasj@amazon.com>
Reviewed-by: Yonatan Nachum <ynachum@amazon.com>
Signed-off-by: Michael Margolin <mrgolin@amazon.com>
Link: https://patch.msgid.link/20250217141623.12428-1-mrgolin@amazon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/umem.c
drivers/infiniband/core/verbs.c