Message ID | 20231029230205.93277-18-dmitry.osipenko@collabora.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers | expand |
On Mon, 30 Oct 2023 02:01:56 +0300 Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote: > To simplify the drm-shmem refcnt handling, we're moving away from > the implicit get_pages() that is used by get_pages_sgt(). From now on > drivers will have to pin pages while they use sgt. V3D driver doesn't > support shrinker, hence pages are pinned and sgt is valid as long as > pages' use-count > 0. > > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > --- > drivers/gpu/drm/v3d/v3d_bo.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c > index 42cd874f6810..0597c6b01b6c 100644 > --- a/drivers/gpu/drm/v3d/v3d_bo.c > +++ b/drivers/gpu/drm/v3d/v3d_bo.c > @@ -47,6 +47,9 @@ void v3d_free_object(struct drm_gem_object *obj) > /* GPU execution may have dirtied any pages in the BO. */ > bo->base.pages_mark_dirty_on_put = true; > > + if (!obj->import_attach) > + drm_gem_shmem_put_pages(&bo->base); > + > drm_gem_shmem_free(&bo->base); > } > > @@ -135,12 +138,18 @@ struct v3d_bo *v3d_bo_create(struct drm_device *dev, struct drm_file *file_priv, > return ERR_CAST(shmem_obj); > bo = to_v3d_bo(&shmem_obj->base); > > - ret = v3d_bo_create_finish(&shmem_obj->base); > + ret = drm_gem_shmem_get_pages(shmem_obj); > if (ret) > goto free_obj; > > + ret = v3d_bo_create_finish(&shmem_obj->base); > + if (ret) > + goto put_pages; > + > return bo; > > +put_pages: > + drm_gem_shmem_put_pages(shmem_obj); > free_obj: > drm_gem_shmem_free(shmem_obj); > return ERR_PTR(ret);
diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c index 42cd874f6810..0597c6b01b6c 100644 --- a/drivers/gpu/drm/v3d/v3d_bo.c +++ b/drivers/gpu/drm/v3d/v3d_bo.c @@ -47,6 +47,9 @@ void v3d_free_object(struct drm_gem_object *obj) /* GPU execution may have dirtied any pages in the BO. */ bo->base.pages_mark_dirty_on_put = true; + if (!obj->import_attach) + drm_gem_shmem_put_pages(&bo->base); + drm_gem_shmem_free(&bo->base); } @@ -135,12 +138,18 @@ struct v3d_bo *v3d_bo_create(struct drm_device *dev, struct drm_file *file_priv, return ERR_CAST(shmem_obj); bo = to_v3d_bo(&shmem_obj->base); - ret = v3d_bo_create_finish(&shmem_obj->base); + ret = drm_gem_shmem_get_pages(shmem_obj); if (ret) goto free_obj; + ret = v3d_bo_create_finish(&shmem_obj->base); + if (ret) + goto put_pages; + return bo; +put_pages: + drm_gem_shmem_put_pages(shmem_obj); free_obj: drm_gem_shmem_free(shmem_obj); return ERR_PTR(ret);
To simplify the drm-shmem refcnt handling, we're moving away from the implicit get_pages() that is used by get_pages_sgt(). From now on drivers will have to pin pages while they use sgt. V3D driver doesn't support shrinker, hence pages are pinned and sgt is valid as long as pages' use-count > 0. Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> --- drivers/gpu/drm/v3d/v3d_bo.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)