Re: [PATCH 1/8] drm/gem: Write down some rules for vmap usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

Am 01.12.20 um 11:34 schrieb Christian König:
[...]
In patch 6 of this series, there's ast cursor code that acquires two BO's reservation locks and vmaps them afterwards. That's probably how you intend to use dma_buf_vmap_local.

However, I think it's more logically to have a vmap callback that only does the actual vmap. This is all that exporters would have to implement.

And with that, build one helper that pins before vmap and one helper that gets the resv lock.

I don't think that this is will work nor is it a good approach.

See the ast cursor handling for example. You need to acquire two BOs here, not just one. And this can't be done cleanly with a single vmap call.

That seems to be a misunderstanding.

I don't mentioned it explicitly, but there's of course another helper that only vmaps and nothing else. This would be useful for cases like the cursor code. So there would be:

 dma_buf_vmap() - pin + vmap
 dma_buf_vmap_local() - lock + vmap
 dma_buf_vmap_locked() - only vmap; caller has set up the BOs

I did some conversion of drivers that use vram and shmem. They occasionally update a buffer (ast cursors) or flush a BO from system memory to HW (udl, cirrus, mgag200). In terms of these 3 interfaces: I never needed dma_buf_vmap() because pinning was never really required here. Almost all of the cases were handled by dma_buf_vmap_local(). And the ast cursor code uses the equivalent of dma_buf_vmap_locked().

The driver exporting the buffer would only have to implement vmap() and pin() interfaces. Each does only its one thing and would assume that the caller holds the lock.

Best regards
Thomas


Regards,
Christian.


I know that it might require some work on exporting drivers. But with your proposal, we probably need another dma-buf callback just for vmap_local. (?) That seems even less appealing to me.

Best regards
Thomas


Trying to shovel both semantics into one interface, depending upon
which implementation we have backing the buffer, doesn't work indeed.

Also on the pin topic, I think neither interface should require
callers to explicitly pin anything. For existing users it should
happen automatically behind the scenes imo, that's what they're
expecting.
-Daniel


I think we could use what we've done for dynamic dma-buf attachment
(which also change locking rules) and just have new functions for the
new way (i.e. short term vmap protected by dma_resv lock. Maybe call
these dma_buf_vmap_local, in the spirit of the new kmap_local which
are currently under discussion. I think _local suffix is better, for
otherwise people might do something silly like

      dma_resv_lock();
      dma_buf_vmap_locked();
      dma_resv_unlock();

      /* actual access maybe even in some other thread */

     dma_buf_resv_lock();
     dma_buf_vunmap_unlocked();
     dma_resv_unlock();

_local suffix is better at telling that the resulting pointer has very
limited use (essentially just local to the calling context, if you
don't change any locking or anything).

_local sounds good.

Best regards
Thomas


I think encouraging importers to call dma_buf_pin/unpin isn't a good
idea. Yes dynamic ones need it, but maybe we should check for that
somehow in the exporterd interface (atm only amdgpu is using it).
-Daniel





Best regards
Thomas



Cheers,
Christian.


That's what I meant with that this approach here is very sprawling :-/
-Daniel

     */
    int drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct dma_buf_map
*map)
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 5e6daa1c982f..7c34cd5ec261 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -137,7 +137,21 @@ struct drm_gem_object_funcs {
         * Returns a virtual address for the buffer. Used by the
         * drm_gem_dmabuf_vmap() helper.
         *
+     * Notes to implementors:
+     *
+     * - Implementations must expect pairs of @vmap and @vunmap to be
+     *   called frequently and should optimize for this case.
+     *
+     * - Implemenations may expect the caller to hold the GEM object's
+     *   reservation lock to protect against concurrent calls and
relocation
+     *   of the GEM object.
+     *
+     * - Implementations may provide additional guarantees (e.g.,
working
+     *   without holding the reservation lock).
+     *
         * This callback is optional.
+     *
+     * See also drm_gem_dmabuf_vmap()
         */
        int (*vmap)(struct drm_gem_object *obj, struct dma_buf_map *map);
@@ -148,6 +162,8 @@ struct drm_gem_object_funcs {
         * drm_gem_dmabuf_vunmap() helper.
         *
         * This callback is optional.
+     *
+     * See also @vmap.
         */
        void (*vunmap)(struct drm_gem_object *obj, struct dma_buf_map
*map);
--
2.29.2


_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer




--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer





_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux