[PATCH rdma-next v2 1/3] RDMA/mlx5: Respect pgsz_bitmap when reducing the DEVX UMEM page size

From: Edward Srouji

Date: Wed Nov 11 2026 - 09:05:04 EST


devx_umem_find_best_pgsize() starts from the largest usable page size
allowed by the user's pgsz_bitmap and halves it until the umem starts
on a page boundary and its length is a multiple of the page size. The
halving ignores pgsz_bitmap, so the umem can be created with a page
size userspace did not allow, although the bitmap is meant to reflect
the HW limits of the intended use of the umem.

Step down to the next smaller size in pgsz_bitmap instead, and fail
the registration if none is left. The default bitmap includes every
power-of-two page size from 4K up, so the result is unchanged when
userspace does not pass one.

The Sashiko AI reviewer found this while reviewing another DEVX UMEM
patch.

Fixes: 7610ab57de56 ("RDMA/mlx5: Allow larger pages in DevX umem")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/linux-rdma/sashiko-outbox-205134@xxxxxxxxxx/
Signed-off-by: Edward Srouji <edwards@xxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/devx.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index fc6f793dcc6584e6a22b40c57e2df8f24579eb14..6c34f2c2a91d0be26352100c243f24789feab3db 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -2320,8 +2320,12 @@ static unsigned int devx_umem_find_best_pgsize(struct ib_umem *umem,
*/
while ((ib_umem_dma_offset(umem, page_size) != 0 ||
(umem->length % page_size) != 0) &&
- page_size > PAGE_SIZE)
- page_size /= 2;
+ page_size > PAGE_SIZE) {
+ pgsz_bitmap &= page_size - 1;
+ if (!pgsz_bitmap)
+ return 0;
+ page_size = rounddown_pow_of_two(pgsz_bitmap);
+ }

return page_size;
}

--
2.49.0