The DSI 6G TX buffer is allocated by msm_gem_kernel_new(), which pins
the buffer object in the KMS address space and returns its IOVA, but the
returned IOVA is ignored. Instead dsi_dma_base_get_6g() calls
msm_gem_get_and_pin_iova() on every DSI command transfer to get the TX
buffer address, and the buffer is never unpinned after the transfer.

As a result the pin count of the TX buffer object grows with every
transmitted DSI command, and when the buffer is freed by
msm_gem_kernel_put(), which drops only the pin taken on allocation,
the object is freed while still pinned:

  msm_obj->pin_count
  WARNING: drivers/gpu/drm/msm/msm_gem.c:173 at update_lru_locked+0x90/0x98
  Call trace:
   update_lru_locked+0x90/0x98 (P)
   put_pages+0x8c/0x104
   msm_gem_free_object+0x1bc/0x244
   drm_gem_object_free+0x1c/0x30
   msm_gem_kernel_put+0xa4/0xb8
   msm_dsi_tx_buf_free+0x2c/0x64
   dsi_unbind+0x20/0x40

Save the IOVA returned on the TX buffer allocation and use it as the DMA
base of command transfers without pinning the buffer again.

Fixes: 9fe041f6fdfe ("drm/msm: Add msm_gem_get_and_pin_iova()")
Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
 drivers/gpu/drm/msm/dsi/dsi_host.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 78f0fd259421..5a6fb1a5a890 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -153,6 +153,7 @@ struct msm_dsi_host {
        /* DSI 6G TX buffer*/
        struct drm_gem_object *tx_gem_obj;
        struct drm_gpuvm *vm;
+       u64 tx_iova;
 
        /* DSI v2 TX buffer */
        void *tx_buf;
@@ -1261,6 +1262,7 @@ int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, 
int size)
 
        msm_gem_object_set_name(msm_host->tx_gem_obj, "tx_gem");
 
+       msm_host->tx_iova = iova;
        msm_host->tx_size = msm_host->tx_gem_obj->size;
 
        return 0;
@@ -1422,14 +1424,13 @@ static int dsi_long_read_resp(u8 *buf, const struct 
mipi_dsi_msg *msg)
 
 int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *dma_base)
 {
-       struct drm_device *dev = msm_host->dev;
-       struct msm_drm_private *priv = dev->dev_private;
-
        if (!dma_base)
                return -EINVAL;
 
-       return msm_gem_get_and_pin_iova(msm_host->tx_gem_obj,
-                               priv->kms->vm, dma_base);
+       /* The TX buffer is pinned on allocation by msm_gem_kernel_new() */
+       *dma_base = msm_host->tx_iova;
+
+       return 0;
 }
 
 int dsi_dma_base_get_v2(struct msm_dsi_host *msm_host, uint64_t *dma_base)
-- 
2.51.0

Reply via email to