RE: [PATCH rdma-next v1 1/1] RDMA/mana_ib: Fix bug in creation of dma regions

From: Konstantin Taranov
Date: Thu Feb 08 2024 - 14:00:20 EST


> From: Long Li <longli@xxxxxxxxxxxxx>
> Sent: Thursday, 8 February 2024 19:43
> To: Konstantin Taranov <kotaranov@xxxxxxxxxxxxxxxxxxx>; Konstantin
> Taranov <kotaranov@xxxxxxxxxxxxx>; sharmaajay@xxxxxxxxxxxxx;
> jgg@xxxxxxxx; leon@xxxxxxxxxx
> Cc: linux-rdma@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> Subject: RE: [PATCH rdma-next v1 1/1] RDMA/mana_ib: Fix bug in creation of
> dma regions
>
> >
> > /* Hardware requires dma region to align to chosen page size */
> > - page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, 0);
> > + page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, virt);
> > if (!page_sz) {
> > ibdev_dbg(&dev->ib_dev, "failed to find page size.\n");
> > return -ENOMEM;
> > }
>
> How about doing:
> page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, force_zero_offset
> ? 0 : virt);
>
> Will this work? This can get rid of the following while loop.
>

I do not think so. I mentioned once, that it was failing for me with existing code
with the 4K-aligned addresses and 8K pages. In this case, we miscalculate the
number of pages. So, we think that it is one 8K page, but it is in fact two.


> > +
> > + if (force_zero_offset) {
> > + while (ib_umem_dma_offset(umem, page_sz) && page_sz >
> > PAGE_SIZE)
> > + page_sz /= 2;
> > + if (ib_umem_dma_offset(umem, page_sz) != 0) {
> > + ibdev_dbg(&dev->ib_dev, "failed to find page size to
> > force zero offset.\n");
> > + return -ENOMEM;
> > + }
> > + }
> > +