From: Robin Murphy <robin.murphy@arm.com>
To: Boris Brezillon <boris.brezillon@collabora.com>,
Rob Herring <robh+dt@kernel.org>,
Tomeu Vizoso <tomeu@tomeuvizoso.net>,
Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>,
Steven Price <steven.price@arm.com>
Cc: stable@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 8/8] drm/panfrost: Make sure the shrinker does not reclaim referenced BOs
Date: Mon, 2 Dec 2019 12:50:20 +0000 [thread overview]
Message-ID: <7258aca4-115d-d511-4c0a-fb3ba142f382@arm.com> (raw)
In-Reply-To: <20191129135908.2439529-9-boris.brezillon@collabora.com>
On 29/11/2019 1:59 pm, Boris Brezillon wrote:
> Userspace might tag a BO purgeable while it's still referenced by GPU
> jobs. We need to make sure the shrinker does not purge such BOs until
> all jobs referencing it are finished.
Nit: for extra robustness, perhaps it's worth using the refcount_t API
rather than bare atomic_t?
Robin.
> Fixes: 013b65101315 ("drm/panfrost: Add madvise and shrinker support")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/panfrost/panfrost_drv.c | 1 +
> drivers/gpu/drm/panfrost/panfrost_gem.h | 6 ++++++
> drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 2 ++
> drivers/gpu/drm/panfrost/panfrost_job.c | 7 ++++++-
> 4 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
> index b406b5243b40..297c0e7304d2 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
> @@ -166,6 +166,7 @@ panfrost_lookup_bos(struct drm_device *dev,
> break;
> }
>
> + atomic_inc(&bo->gpu_usecount);
> job->mappings[i] = mapping;
> }
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h
> index ca1bc9019600..b3517ff9630c 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_gem.h
> +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h
> @@ -30,6 +30,12 @@ struct panfrost_gem_object {
> struct mutex lock;
> } mappings;
>
> + /*
> + * Count the number of jobs referencing this BO so we don't let the
> + * shrinker reclaim this object prematurely.
> + */
> + atomic_t gpu_usecount;
> +
> bool noexec :1;
> bool is_heap :1;
> };
> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
> index b36df326c860..288e46c40673 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
> @@ -41,6 +41,8 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)
> struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
> struct panfrost_gem_object *bo = to_panfrost_bo(obj);
>
> + if (atomic_read(&bo->gpu_usecount))
> + return false;
>
> if (!mutex_trylock(&shmem->pages_lock))
> return false;
> diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
> index c85d45be3b5e..2b12aa87ff32 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_job.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -270,8 +270,13 @@ static void panfrost_job_cleanup(struct kref *ref)
> dma_fence_put(job->render_done_fence);
>
> if (job->mappings) {
> - for (i = 0; i < job->bo_count; i++)
> + for (i = 0; i < job->bo_count; i++) {
> + if (!job->mappings[i])
> + break;
> +
> + atomic_dec(&job->mappings[i]->obj->gpu_usecount);
> panfrost_gem_mapping_put(job->mappings[i]);
> + }
> kvfree(job->mappings);
> }
>
>
next prev parent reply other threads:[~2019-12-02 12:50 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191129135908.2439529-1-boris.brezillon@collabora.com>
2019-11-29 13:59 ` [PATCH 1/8] drm/panfrost: Make panfrost_job_run() return an ERR_PTR() instead of NULL Boris Brezillon
2019-11-29 14:19 ` Steven Price
2019-11-29 14:31 ` Boris Brezillon
2019-11-29 14:38 ` Steven Price
2019-11-29 19:32 ` Boris Brezillon
2019-11-29 13:59 ` [PATCH 2/8] drm/panfrost: Fix a race in panfrost_ioctl_madvise() Boris Brezillon
2019-11-29 14:24 ` Steven Price
2019-11-29 14:33 ` Boris Brezillon
2019-11-29 14:40 ` Steven Price
2019-11-29 20:07 ` Daniel Vetter
2019-11-29 21:45 ` Boris Brezillon
2019-12-05 23:08 ` Rob Herring
2019-12-06 7:53 ` Boris Brezillon
2019-12-06 8:08 ` Boris Brezillon
2019-11-29 13:59 ` [PATCH 3/8] drm/panfrost: Fix a BO leak in panfrost_ioctl_mmap_bo() Boris Brezillon
2019-11-29 14:26 ` Steven Price
2019-11-29 13:59 ` [PATCH 4/8] drm/panfrost: Fix a race in panfrost_gem_free_object() Boris Brezillon
2019-11-29 14:28 ` Steven Price
2019-11-29 13:59 ` [PATCH 5/8] drm/panfrost: Open/close the perfcnt BO Boris Brezillon
2019-11-29 14:34 ` Steven Price
2019-11-29 13:59 ` [PATCH 6/8] drm/panfrost: Make sure imported/exported BOs are never purged Boris Brezillon
2019-11-29 14:14 ` Boris Brezillon
2019-11-29 14:45 ` Steven Price
2019-11-29 14:52 ` Boris Brezillon
2019-11-29 20:12 ` Daniel Vetter
2019-11-29 21:09 ` Boris Brezillon
2019-12-02 8:52 ` Daniel Vetter
2019-12-02 9:50 ` Boris Brezillon
2019-11-29 13:59 ` [PATCH 7/8] drm/panfrost: Add the panfrost_gem_mapping concept Boris Brezillon
2019-11-29 15:37 ` Steven Price
2019-11-29 20:14 ` Daniel Vetter
2019-11-29 21:36 ` Boris Brezillon
2019-12-02 8:55 ` Daniel Vetter
2019-12-02 9:13 ` Boris Brezillon
2019-12-02 9:44 ` Daniel Vetter
2019-12-04 11:41 ` Steven Price
2019-11-29 13:59 ` [PATCH 8/8] drm/panfrost: Make sure the shrinker does not reclaim referenced BOs Boris Brezillon
2019-11-29 15:48 ` Steven Price
2019-11-29 16:07 ` Boris Brezillon
2019-11-29 16:12 ` Steven Price
2019-12-02 12:50 ` Robin Murphy [this message]
2019-12-02 13:32 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7258aca4-115d-d511-4c0a-fb3ba142f382@arm.com \
--to=robin.murphy@arm.com \
--cc=alyssa.rosenzweig@collabora.com \
--cc=boris.brezillon@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=robh+dt@kernel.org \
--cc=stable@vger.kernel.org \
--cc=steven.price@arm.com \
--cc=tomeu@tomeuvizoso.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).