Commit 809d9c72 authored by Dmitry Osipenko's avatar Dmitry Osipenko

dma-buf: Move dma_buf_attach() to dynamic locking specification

Move dma-buf attachment API functions to the dynamic locking specification
by taking the reservation lock around the mapping operations. The strict
locking convention prevents deadlock situations for dma-buf importers and
exporters.
Acked-by: default avatarSumit Semwal <sumit.semwal@linaro.org>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarDmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221017172229.42269-17-dmitry.osipenko@collabora.com
parent 34c7797f
...@@ -859,8 +859,8 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, ...@@ -859,8 +859,8 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
dma_buf_is_dynamic(dmabuf)) { dma_buf_is_dynamic(dmabuf)) {
struct sg_table *sgt; struct sg_table *sgt;
if (dma_buf_is_dynamic(attach->dmabuf)) {
dma_resv_lock(attach->dmabuf->resv, NULL); dma_resv_lock(attach->dmabuf->resv, NULL);
if (dma_buf_is_dynamic(attach->dmabuf)) {
ret = dmabuf->ops->pin(attach); ret = dmabuf->ops->pin(attach);
if (ret) if (ret)
goto err_unlock; goto err_unlock;
...@@ -873,7 +873,6 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, ...@@ -873,7 +873,6 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
ret = PTR_ERR(sgt); ret = PTR_ERR(sgt);
goto err_unpin; goto err_unpin;
} }
if (dma_buf_is_dynamic(attach->dmabuf))
dma_resv_unlock(attach->dmabuf->resv); dma_resv_unlock(attach->dmabuf->resv);
attach->sgt = sgt; attach->sgt = sgt;
attach->dir = DMA_BIDIRECTIONAL; attach->dir = DMA_BIDIRECTIONAL;
...@@ -890,7 +889,6 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, ...@@ -890,7 +889,6 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
dmabuf->ops->unpin(attach); dmabuf->ops->unpin(attach);
err_unlock: err_unlock:
if (dma_buf_is_dynamic(attach->dmabuf))
dma_resv_unlock(attach->dmabuf->resv); dma_resv_unlock(attach->dmabuf->resv);
dma_buf_detach(dmabuf, attach); dma_buf_detach(dmabuf, attach);
...@@ -937,21 +935,19 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) ...@@ -937,21 +935,19 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
if (WARN_ON(!dmabuf || !attach)) if (WARN_ON(!dmabuf || !attach))
return; return;
if (attach->sgt) {
if (dma_buf_is_dynamic(attach->dmabuf))
dma_resv_lock(attach->dmabuf->resv, NULL); dma_resv_lock(attach->dmabuf->resv, NULL);
if (attach->sgt) {
__unmap_dma_buf(attach, attach->sgt, attach->dir); __unmap_dma_buf(attach, attach->sgt, attach->dir);
if (dma_buf_is_dynamic(attach->dmabuf)) { if (dma_buf_is_dynamic(attach->dmabuf))
dmabuf->ops->unpin(attach); dmabuf->ops->unpin(attach);
dma_resv_unlock(attach->dmabuf->resv);
}
} }
dma_resv_lock(dmabuf->resv, NULL);
list_del(&attach->node); list_del(&attach->node);
dma_resv_unlock(dmabuf->resv); dma_resv_unlock(dmabuf->resv);
if (dmabuf->ops->detach) if (dmabuf->ops->detach)
dmabuf->ops->detach(dmabuf, attach); dmabuf->ops->detach(dmabuf, attach);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment