From: "Maíra Canal" <mcanal@igalia.com>
To: Aleksei Riapolov <tsbol@icloud.com>, mwen@igalia.com
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/v3d: Fix double free of the sg_table when a PRIME import fails
Date: Wed, 18 Nov 2026 09:54:12 -0300 [thread overview]
Message-ID: <99676bca-eba1-46e8-a23a-923bffdc574e@igalia.com> (raw)
In-Reply-To: <20261114164451.9222-1-tsbol@icloud.com>
Hi Aleksei,
On 14/11/26 13:44, Aleksei Riapolov wrote:
[...]
>
> Hand the table back to its owner before freeing the object: with
> shmem->sgt cleared, drm_gem_shmem_release() leaves it alone and it is
> unmapped once, by the exporter, on drm_gem_prime_import_dev()'s error
> path. With this change the same test gets -ENOSPC from the failing
> import in each of three consecutive fills and the kernel log stays
> clean.
The issue you reported is real and makes sense, but your fix only treats
the symptom, not the problem.
V3D allocates the GPU address inside the gem_prime_import_sg_table()
callback, before the core marks the object as imported. No teardown
would be correct at that point.
I'd rather move the allocation after the import completes. Implement
.gem_prime_import as a wrapper around drm_gem_prime_import() and call
v3d_bo_create_finish() once it returns. At that point import_attach is
set, so drm_gem_object_put() takes the regular import teardown path,
which unmaps the sg_table once and detaches.
Best regards,
- Maíra
>
> A reproducer is available on request.
>
> Fixes: 40609d4820b2 ("drm/v3d: Use the new shmem helpers to reduce driver boilerplate.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Aleksei Riapolov <tsbol@icloud.com>
> ---
> drivers/gpu/drm/v3d/v3d_bo.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c
> index db95a2f..48c7807 100644
> --- a/drivers/gpu/drm/v3d/v3d_bo.c
> +++ b/drivers/gpu/drm/v3d/v3d_bo.c
> @@ -185,6 +185,14 @@ v3d_prime_import_sg_table(struct drm_device *dev,
>
> ret = v3d_bo_create_finish(obj);
> if (ret) {
> + /*
> + * obj->import_attach is only set by drm_gem_prime_import_dev()
> + * after we return, so drm_gem_shmem_release() would treat this
> + * object as native and unmap/free the attachment's sg_table,
> + * which the caller unmaps again on its error path. Hand the
> + * table back to its owner before freeing the object.
> + */
> + to_v3d_bo(obj)->base.sgt = NULL;
> drm_gem_shmem_free(&to_v3d_bo(obj)->base);
> return ERR_PTR(ret);
> }
prev parent reply other threads:[~2026-11-18 12:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 16:44 Aleksei Riapolov
2026-11-18 12:54 ` 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=99676bca-eba1-46e8-a23a-923bffdc574e@igalia.com \
--to=mcanal@igalia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mwen@igalia.com \
--cc=tsbol@icloud.com \
/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®