[PATCH v15 11/23] dma-resv: Add kref_put_dma_resv()

Christian König christian.koenig at amd.com
Mon Aug 28 10:21:23 UTC 2023


Am 27.08.23 um 19:54 schrieb Dmitry Osipenko:
> Add simple kref_put_dma_resv() helper that wraps around kref_put_ww_mutex()
> for drivers that needs to lock dma-resv on kref_put().
>
> It's not possible to easily add this helper to kref.h because of the
> headers inclusion dependency, hence add it to dma-resv.h.

I was never really a big fan of kref_put_mutex() in the first place.

The main advantage comes from the included memory barrier, but this 
actually doesn't work like most people think it works and is usually 
pretty dangerous.

And IIRC this was done because of the some special behavior mutexes have 
with memory barriers and that isn't necessary with ww-mutex.

Christian.

>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko at collabora.com>
> ---
>   include/linux/dma-resv.h | 9 +++++++++
>   1 file changed, 9 insertions(+)
>
> diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
> index 8d0e34dad446..c5cf302e4194 100644
> --- a/include/linux/dma-resv.h
> +++ b/include/linux/dma-resv.h
> @@ -41,6 +41,7 @@
>   
>   #include <linux/ww_mutex.h>
>   #include <linux/dma-fence.h>
> +#include <linux/kref.h>
>   #include <linux/slab.h>
>   #include <linux/seqlock.h>
>   #include <linux/rcupdate.h>
> @@ -464,6 +465,14 @@ static inline void dma_resv_unlock(struct dma_resv *obj)
>   	ww_mutex_unlock(&obj->lock);
>   }
>   
> +static inline int kref_put_dma_resv(struct kref *kref,
> +				    void (*release)(struct kref *kref),
> +				    struct dma_resv *resv,
> +				    struct ww_acquire_ctx *ctx)
> +{
> +	return kref_put_ww_mutex(kref, release, &resv->lock, ctx);
> +}
> +
>   void dma_resv_init(struct dma_resv *obj);
>   void dma_resv_fini(struct dma_resv *obj);
>   int dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences);



More information about the dri-devel mailing list