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 v2] drm/v3d: Fix double free of the sg_table when a PRIME import fails
Date: Fri, 20 Nov 2026 13:29:27 -0300 [thread overview]
Message-ID: <f3997d67-8d39-4892-b144-d3ee25050d86@igalia.com> (raw)
In-Reply-To: <20261119144339.43896-1-tsbol@icloud.com>
Hi Aleksei,
On 19/11/26 11:43, Aleksei Riapolov wrote:
[...]
>
> The error path frees the object with drm_gem_shmem_free(), as
> v3d_bo_create() does, and not with drm_gem_object_put():
> v3d_free_object() expects a BO that v3d_bo_create_finish() completed.
> For one whose node was never inserted it would clear page table entries
> starting at page 0, decrement bo_stats and call drm_mm_remove_node() on
> a node that is not allocated. With drm_gem_object_put() there, the
> failing import oopses in drm_mm_remove_node(), called from
> v3d_free_object().
You don't need to explain what you didn't do, only what you did.
Also, the following paragraphs can be deleted. They are not clarifying
at all.
>
> v3d_bo_create_finish() now runs after obj->resv has been pointed at the
> reservation object of the dma-buf, so drm_gem_shmem_get_pages_sgt()
> takes that lock instead of the private lock of a new object, and an
> import can return -EINTR if a signal arrives while it waits for it.
>
> With this change, on the same board and kernel:
>
> - the failing import returns -ENOSPC in each of three consecutive
> fills, and after 50 such failures debugfs dma_buf/bufinfo lists no
> dma-buf;
> - a v3d BO imported back into v3d through a second file is the same
> BO at the same offset over 1000 iterations, with bo_stats back at
> its starting value;
> - a vc4 dumb buffer imported into v3d can be mapped, written, read
> and closed;
> - under labwc, glmark2-es2-wayland runs, and mpv playing 4K HEVC from
> the hardware decoder imports the decoder's dma-heap buffers into
> v3d about 2500 times, none of which is left attached afterwards;
> the time an import takes and the number of dropped frames are the
> same as with the unpatched module, with and without slub_debug.
>
> The kernel log stays clean throughout. Other V3D generations were not
> tested.
>
> A reproducer is available on request.
As a general note, please make this commit message more readable for
humans, not LLMs.
>
> Fixes: 40609d4820b2 ("drm/v3d: Use the new shmem helpers to reduce driver boilerplate.")
> Cc: stable@vger.kernel.org
> Suggested-by: Maíra Canal <mcanal@igalia.com>
> Signed-off-by: Aleksei Riapolov <tsbol@icloud.com>
> ---
> v2: Allocate the GPU address after the import has completed, in a
> .gem_prime_import wrapper, instead of clearing shmem->sgt on the
> error path of the callback (Maíra).
> v1: https://lore.kernel.org/all/20261114164451.9222-1-tsbol@icloud.com/
>
> For stable: drm_gem_is_imported() was added in v6.15, so earlier trees
> need obj->import_attach in the wrapper.
>
> drivers/gpu/drm/v3d/v3d_bo.c | 17 +++++++++++++----
> drivers/gpu/drm/v3d/v3d_drv.c | 3 ++-
> drivers/gpu/drm/v3d/v3d_drv.h | 5 ++---
> 3 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c
> index db95a2f..34aca97 100644
> --- a/drivers/gpu/drm/v3d/v3d_bo.c
> +++ b/drivers/gpu/drm/v3d/v3d_bo.c
> @@ -172,17 +172,26 @@ free_obj:
> }
>
> struct drm_gem_object *
> -v3d_prime_import_sg_table(struct drm_device *dev,
> - struct dma_buf_attachment *attach,
> - struct sg_table *sgt)
> +v3d_prime_import(struct drm_device *dev, struct dma_buf *dma_buf)
> {
> struct drm_gem_object *obj;
> int ret;
>
> - obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt);
> + obj = drm_gem_prime_import(dev, dma_buf);
> if (IS_ERR(obj))
> return obj;
>
> + /* A dma-buf exported by this device comes back as the BO it was
> + * exported from, which already has its GPU address.
> + */
How about "/* Self-import returns the native BO, already mapped. */"?
> + if (!drm_gem_is_imported(obj))
> + return obj;
> +
> + /* The GPU address is allocated only now that the core has set
> + * obj->import_attach, so that a failure here is torn down as an
> + * import: the sg_table is unmapped once and the attachment is
> + * detached.
> + */
This comment is superfluous. Please, delete it.
Apart from this issues, it looks good to me. I believe we will be able
to merge it in v3.
Best regards,
- Maíra
prev parent reply other threads:[~2026-11-20 16:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 14:43 Aleksei Riapolov
2026-11-20 16:29 ` 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=f3997d67-8d39-4892-b144-d3ee25050d86@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®