From: Rob Clark <robdclark@xxxxxxxxxxxx> For VM_BIND, in the first step, we just want to get the backing pages, but defer creating the vma until the map/unmap/ops are evaluated. Signed-off-by: Rob Clark <robdclark@xxxxxxxxxxxx> --- drivers/gpu/drm/msm/msm_gem_submit.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 8a4f4c403404..51c92fe1146f 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -292,12 +292,16 @@ static int submit_fence_sync(struct msm_gem_submit *submit) return ret; } -static int submit_pin_objects(struct msm_gem_submit *submit) +static int submit_pin_vmas(struct msm_gem_submit *submit) { - struct msm_drm_private *priv = submit->dev->dev_private; - int i, ret = 0; + int ret = 0; - for (i = 0; i < submit->nr_bos; i++) { + /* + * First loop, before holding the LRU lock, avoids holding the + * LRU lock while calling msm_gem_pin_vma_locked (which could + * trigger get_pages()) + */ + for (int i = 0; i < submit->nr_bos; i++) { struct drm_gem_object *obj = submit->bos[i].obj; struct drm_gpuva *vma; @@ -315,6 +319,13 @@ static int submit_pin_objects(struct msm_gem_submit *submit) submit->bos[i].iova = vma->va.addr; } + return ret; +} + +static void submit_pin_objects(struct msm_gem_submit *submit) +{ + struct msm_drm_private *priv = submit->dev->dev_private; + /* * A second loop while holding the LRU lock (a) avoids acquiring/dropping * the LRU lock for each individual bo, while (b) avoiding holding the @@ -323,14 +334,12 @@ static int submit_pin_objects(struct msm_gem_submit *submit) * could trigger deadlock with the shrinker). */ mutex_lock(&priv->lru.lock); - for (i = 0; i < submit->nr_bos; i++) { + for (int i = 0; i < submit->nr_bos; i++) { msm_gem_pin_obj_locked(submit->bos[i].obj); } mutex_unlock(&priv->lru.lock); submit->bos_pinned = true; - - return ret; } static void submit_unpin_objects(struct msm_gem_submit *submit) @@ -760,10 +769,12 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, goto out; } - ret = submit_pin_objects(submit); + ret = submit_pin_vmas(submit); if (ret) goto out; + submit_pin_objects(submit); + for (i = 0; i < args->nr_cmds; i++) { struct drm_gem_object *obj; uint64_t iova; -- 2.47.1