mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Maíra Canal" <mcanal@igalia.com>
To: Kazuki Hanai <hnkz.64@gmail.com>,
	mripard@kernel.org, dave.stevenson@raspberrypi.com
Cc: kernel-list@raspberrypi.com, maarten.lankhorst@linux.intel.com,
	tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
	eric@anholt.net, bbrezillon@kernel.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] drm/vc4: Hold a GEM reference while purging userspace BOs
Date: Mon, 14 Sep 2026 14:34:41 -0300	[thread overview]
Message-ID: <c1388b5f-9077-4161-8fd8-3b8ebf24fbde@igalia.com> (raw)
In-Reply-To: <20260830130700.680041-1-hnkz.64@gmail.com>

Hi Kazuki,

On 30/08/26 10:07, Kazuki Hanai wrote:
> vc4_bo_userspace_cache_purge() removes a BO from the purgeable list and
> then drops the list lock before taking the BO madvise lock. A concurrent
> final GEM put can therefore release the BO while the purge path still
> holds only a raw pointer.
> 
> Acquire a non-zero GEM reference while the purgeable list lock still
> protects the lookup. If final release has already started, drop the list
> lock so the release path can remove the entry and retry. Put the temporary
> reference after dropping the madvise lock to avoid recursing into final
> release while that lock is held.
> 
> Fixes: b9f19259b84d ("drm/vc4: Add the DRM_IOCTL_VC4_GEM_MADVISE ioctl")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kazuki Hanai <hnkz.64@gmail.com>
> ---
>   drivers/gpu/drm/vc4/vc4_bo.c | 14 ++++++++++++++
>   1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
> index 49ea2ed0996b4..5289e69f3345f 100644
> --- a/drivers/gpu/drm/vc4/vc4_bo.c
> +++ b/drivers/gpu/drm/vc4/vc4_bo.c
> @@ -319,6 +319,19 @@ static void vc4_bo_userspace_cache_purge(struct drm_device *dev)
>   		struct drm_gem_object *obj = &bo->base.base;
>   		size_t purged_size = 0;
>   
> +		/*
> +		 * The last GEM reference can be dropped concurrently. Its free
> +		 * callback removes the BO from this list before releasing it, so
> +		 * the list lock makes an unless-zero get safe. Never carry only a
> +		 * raw list pointer across the lock drop below.
> +		 */
> +		if (!kref_get_unless_zero(&obj->refcount)) {
> +			mutex_unlock(&vc4->purgeable.lock);
> +			cond_resched();
> +			mutex_lock(&vc4->purgeable.lock);
> +			continue;
> +		}

Hum, your fix doesn't look correct to me. First, I don't understand why
you are using something like cond_resched() here. Next, with this
approach, the BO with refcount=0 will never be removed from the list.

> +
>   		vc4_bo_remove_from_purgeable_pool_locked(bo);

What you could do instead is calling:

if (!kref_get_unless_zero(&obj->refcount))
       continue;

here.

Best regards,
- Maíra

>   
>   		/* Release the purgeable lock while we're purging the BO so
> @@ -345,6 +358,7 @@ static void vc4_bo_userspace_cache_purge(struct drm_device *dev)
>   			vc4_bo_purge(obj);
>   		}
>   		mutex_unlock(&bo->madv_lock);
> +		drm_gem_object_put(obj);
>   		mutex_lock(&vc4->purgeable.lock);
>   
>   		if (purged_size) {


      reply	other threads:[~2026-09-14 17:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 13:07 Kazuki Hanai
2026-09-14 17:34 ` Maíra Canal [this message]

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=c1388b5f-9077-4161-8fd8-3b8ebf24fbde@igalia.com \
    --to=mcanal@igalia.com \
    --cc=airlied@gmail.com \
    --cc=bbrezillon@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eric@anholt.net \
    --cc=hnkz.64@gmail.com \
    --cc=kernel-list@raspberrypi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=tzimmermann@suse.de \
    /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

all inboxes | Powered by JetHome®