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: [email protected]
Suggested-by: Maíra Canal <[email protected]>
Signed-off-by: Aleksei Riapolov <[email protected]>
---
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/[email protected]/

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


Reply via email to