Skip to contentSkip to conversation

RDMA/umem: Fix double dma_buf_unpin in failure path

PATCH Applied Jacob Moroni 2 participants 2 messages Feb 24 – Feb 25 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA/umem: Fix double dma_buf_unpin in failure path

In ib_umem_dmabuf_get_pinned_with_dma_device(), the call to ib_umem_dmabuf_map_pages() can fail. If this occurs, the dmabuf is immediately unpinned but the umem_dmabuf->pinned flag is still set. Then, when ib_umem_release() is called, it calls ib_umem_dmabuf_revoke() which will call dma_buf_unpin() again.

Fix this by removing the immediate unpin upon failure and just let the ib_umem_release/revoke path handle it. This also ensures the proper unmap-unpin unwind ordering if the dmabuf_map_pages call happened to fail due to dma_resv_wait_timeout (and therefore has a non-NULL umem_dmabuf->sgt).

Fixes 1e4df4a21c5a ("RDMA/umem: Allow pinned dmabuf umem usage")

---
v1 -> v2:
- Removed an accidental blank line.

 drivers/infiniband/core/umem_dmabuf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/infiniband/core/umem_dmabuf.c +1 -3
index f5298c33e..d30f24b90 100644
@@ -218,13 +218,11 @@ ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,
 
 	err = ib_umem_dmabuf_map_pages(umem_dmabuf);
 	if (err)
-		goto err_unpin;
+		goto err_release;
 	dma_resv_unlock(umem_dmabuf->attach->dmabuf->resv);
 
 	return umem_dmabuf;
 
-err_unpin:
-	dma_buf_unpin(umem_dmabuf->attach);
 err_release:
 	dma_resv_unlock(umem_dmabuf->attach->dmabuf->resv);
 	ib_umem_release(&umem_dmabuf->umem);
Signature · 1 line
2.53.0.414.gf7e9f6c205-goog
#1 lore raw
Quoted 6 lines · Jacob Moroni

In ib_umem_dmabuf_get_pinned_with_dma_device(), the call to ib_umem_dmabuf_map_pages() can fail. If this occurs, the dmabuf is immediately unpinned but the umem_dmabuf->pinned flag is still set. Then, when ib_umem_release() is called, it calls ib_umem_dmabuf_revoke() which will call dma_buf_unpin() again.

Quoted 7 lines

Fix this by removing the immediate unpin upon failure and just let the ib_umem_release/revoke path handle it. This also ensures the proper unmap-unpin unwind ordering if the dmabuf_map_pages call happened to fail due to dma_resv_wait_timeout (and therefore has a non-NULL umem_dmabuf->sgt).

[...]

Applied, thanks!

[1/1] RDMA/umem: Fix double dma_buf_unpin in failure path
(no commit info)

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>