mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Maíra Canal" <mcanal@igalia.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
	Melissa Wen <mwen@igalia.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Iago Toral Quiroga <itoral@igalia.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] drm/v3d: release CPU job resources on pre-init failures
Date: Mon, 27 Jul 2026 17:11:39 -0300	[thread overview]
Message-ID: <d8f9dbd9-0af1-4761-b577-0ad0b46a2ed4@igalia.com> (raw)
In-Reply-To: <20260718071047.3037514-1-lgs201920130244@gmail.com>

Hi Guangshuo,

While reviewing your patch, I noticed that this patch is no longer
needed in drm-misc-next due to commit f59d986943af ("drm/v3d: Convert
submit helpers to operate on struct v3d_submit").

Considering that this is just a simple error in the error path, I
believe it's okay to leave stable as it is, considering that the issue
is already addressed in drm-misc-next.

Best regards,
- Maíra

On 18/07/26 04:10, Guangshuo Li wrote:
> The changes referenced by the Fixes tags moved CPU job resource cleanup
> to v3d_cpu_job_free(), the CPU job kref destructor.
> 
> However, CPU job extensions are parsed before v3d_job_init() has
> successfully installed that destructor. Timestamp and performance query
> arrays, their syncobj references, and the indirect CSD GEM reference can
> therefore be acquired before the CPU job is managed by the kref cleanup
> path.
> 
> If a later pre-init validation fails, or if v3d_job_init() itself fails,
> the CPU job can be cleaned up or deallocated without running
> v3d_cpu_job_free(). Those extension resources are then leaked.
> 
> Move the CPU-job-owned resource release into a helper and call it both
> from the normal CPU job destructor and from the pre-init error paths.
> 
> Fixes: b0fe80c0b925 ("drm/v3d: Fix use-after-free of CPU job query arrays on error path")
> Fixes: 6eb6e5acafa4 ("drm/v3d: Release indirect CSD GEM reference on CPU job free")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> v3:
>    - Do not call v3d_cpu_job_free_resources() after v3d_get_extensions()
>      fails, since v3d_get_extensions() already handles the cleanup
>      internally, as pointed out by Maíra Canal.
> 
> v2:
>    - Rebase onto drm-misc-fixes.
>    - Fold the indirect CSD GEM pre-init failure fix into this patch.
>    - Drop unnecessary pointer and count resets after releasing resources,
>      as suggested by Maíra Canal.
> 
>   drivers/gpu/drm/v3d/v3d_submit.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
> index 7682b24f13ec..77e94c25b2af 100644
> --- a/drivers/gpu/drm/v3d/v3d_submit.c
> +++ b/drivers/gpu/drm/v3d/v3d_submit.c
> @@ -127,10 +127,8 @@ v3d_render_job_free(struct kref *ref)
>   }
>   
>   static void
> -v3d_cpu_job_free(struct kref *ref)
> +v3d_cpu_job_free_resources(struct v3d_cpu_job *job)
>   {
> -	struct v3d_cpu_job *job = container_of(ref, struct v3d_cpu_job,
> -					       base.refcount);
>   
>   	v3d_timestamp_query_info_free(&job->timestamp_query,
>   				      job->timestamp_query.count);
> @@ -140,7 +138,15 @@ v3d_cpu_job_free(struct kref *ref)
>   
>   	if (job->indirect_csd.indirect)
>   		drm_gem_object_put(job->indirect_csd.indirect);
> +}
> +
> +static void
> +v3d_cpu_job_free(struct kref *ref)
> +{
> +	struct v3d_cpu_job *job = container_of(ref, struct v3d_cpu_job,
> +					       base.refcount);
>   
> +	v3d_cpu_job_free_resources(job);
>   	v3d_job_free(ref);
>   }
>   
> @@ -1320,12 +1326,14 @@ v3d_submit_cpu_ioctl(struct drm_device *dev, void *data,
>   	/* Every CPU job must have a CPU job user extension */
>   	if (!cpu_job->job_type) {
>   		drm_dbg(dev, "CPU job must have a CPU job user extension.\n");
> +		v3d_cpu_job_free_resources(cpu_job);
>   		ret = -EINVAL;
>   		goto fail;
>   	}
>   
>   	if (args->bo_handle_count != cpu_job_bo_handle_count[cpu_job->job_type]) {
>   		drm_dbg(dev, "This CPU job was not submitted with the proper number of BOs.\n");
> +		v3d_cpu_job_free_resources(cpu_job);
>   		ret = -EINVAL;
>   		goto fail;
>   	}
> @@ -1335,6 +1343,7 @@ v3d_submit_cpu_ioctl(struct drm_device *dev, void *data,
>   	ret = v3d_job_init(v3d, file_priv, &cpu_job->base,
>   			   v3d_cpu_job_free, 0, &se, V3D_CPU);
>   	if (ret) {
> +		v3d_cpu_job_free_resources(cpu_job);
>   		v3d_job_deallocate((void *)&cpu_job);
>   		goto fail;
>   	}


      reply	other threads:[~2026-07-27 20:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18  7:10 Guangshuo Li
2026-07-27 20:11 ` 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=d8f9dbd9-0af1-4761-b577-0ad0b46a2ed4@igalia.com \
    --to=mcanal@igalia.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=itoral@igalia.com \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=mwen@igalia.com \
    --cc=simona@ffwll.ch \
    --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®