Re: [PATCH v19 24/30] drm/shmem-helper: Optimize unlocked get_pages_sgt()
From: Boris Brezillon
Date: Thu Jan 25 2024 - 04:38:52 EST
On Fri, 5 Jan 2024 21:46:18 +0300
Dmitry Osipenko <dmitry.osipenko@xxxxxxxxxxxxx> wrote:
> SGT isn't refcounted. Once SGT pointer has been obtained, it remains the
> same for both locked and unlocked get_pages_sgt(). Return cached SGT
> directly without taking a potentially expensive lock.
>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@xxxxxxxxxxxxx>
Reviewed-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
but I'm wondering if we should have made this change directly in
'drm/shmem-helper: Change sgt allocation policy'.
> ---
> drivers/gpu/drm/drm_gem_shmem_helper.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index 8fd7851c088b..e6e6e693ab95 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -962,6 +962,18 @@ struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_shmem_object *shmem)
> drm_WARN_ON(obj->dev, drm_gem_shmem_is_purgeable(shmem)))
> return ERR_PTR(-EBUSY);
>
> + /*
> + * Drivers that use shrinker should take into account that shrinker
> + * may relocate BO, thus invalidating the returned SGT pointer.
> + * Such drivers should pin GEM while they use SGT.
> + *
> + * Drivers that don't use shrinker should take into account that
> + * SGT is released together with the GEM pages. Pages should be kept
> + * alive while SGT is used.
> + */
> + if (shmem->sgt)
> + return shmem->sgt;
> +
> ret = dma_resv_lock_interruptible(shmem->base.resv, NULL);
> if (ret)
> return ERR_PTR(ret);