[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <192b9a30-6f15-3702-c679-c3f26b76c9ef@amd.com>
Date: Thu, 1 Sep 2022 09:16:29 +0200
From: Christian König <christian.koenig@....com>
To: Dmitry Osipenko <dmitry.osipenko@...labora.com>,
David Airlie <airlied@...ux.ie>,
Gerd Hoffmann <kraxel@...hat.com>,
Gurchetan Singh <gurchetansingh@...omium.org>,
Chia-I Wu <olvaffe@...il.com>, Daniel Vetter <daniel@...ll.ch>,
Daniel Almeida <daniel.almeida@...labora.com>,
Gert Wollny <gert.wollny@...labora.com>,
Gustavo Padovan <gustavo.padovan@...labora.com>,
Daniel Stone <daniel@...ishbar.org>,
Tomeu Vizoso <tomeu.vizoso@...labora.com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
Rob Clark <robdclark@...il.com>,
Sumit Semwal <sumit.semwal@...aro.org>,
"Pan, Xinhui" <Xinhui.Pan@....com>,
Thierry Reding <thierry.reding@...il.com>,
Tomasz Figa <tfiga@...omium.org>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Alex Deucher <alexander.deucher@....com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@...el.com>,
Tvrtko Ursulin <tvrtko.ursulin@...ux.intel.com>,
Thomas Hellström <thomas_os@...pmail.org>,
Qiang Yu <yuq825@...il.com>,
Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Amol Maheshwari <amahesh@....qualcomm.com>,
Jason Gunthorpe <jgg@...pe.ca>,
Leon Romanovsky <leon@...nel.org>,
Juergen Gross <jgross@...e.com>,
Stefano Stabellini <sstabellini@...nel.org>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@...m.com>,
Tomi Valkeinen <tomba@...nel.org>,
Russell King <linux@...linux.org.uk>,
Lucas Stach <l.stach@...gutronix.de>,
Christian Gmeiner <christian.gmeiner@...il.com>
Cc: dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
Dmitry Osipenko <digetx@...il.com>,
linux-media@...r.kernel.org, linaro-mm-sig@...ts.linaro.org,
amd-gfx@...ts.freedesktop.org, intel-gfx@...ts.freedesktop.org,
kernel@...labora.com, virtualization@...ts.linux-foundation.org,
linux-rdma@...r.kernel.org, linux-arm-msm@...r.kernel.org
Subject: Re: [PATCH v4 19/21] dma-buf: Document dynamic locking convention
Am 31.08.22 um 17:37 schrieb Dmitry Osipenko:
> Add documentation for the dynamic locking convention. The documentation
> tells dma-buf API users when they should take the reservation lock and
> when not.
>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@...labora.com>
Reviewed-by: Christian König <christian.koenig@....com>
> ---
> Documentation/driver-api/dma-buf.rst | 6 +++
> drivers/dma-buf/dma-buf.c | 64 ++++++++++++++++++++++++++++
> 2 files changed, 70 insertions(+)
>
> diff --git a/Documentation/driver-api/dma-buf.rst b/Documentation/driver-api/dma-buf.rst
> index 36a76cbe9095..622b8156d212 100644
> --- a/Documentation/driver-api/dma-buf.rst
> +++ b/Documentation/driver-api/dma-buf.rst
> @@ -119,6 +119,12 @@ DMA Buffer ioctls
>
> .. kernel-doc:: include/uapi/linux/dma-buf.h
>
> +DMA-BUF locking convention
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +.. kernel-doc:: drivers/dma-buf/dma-buf.c
> + :doc: locking convention
> +
> Kernel Functions and Structures Reference
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index d9130486cb8f..97ce884fad76 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -794,6 +794,70 @@ static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach,
> return sg_table;
> }
>
> +/**
> + * DOC: locking convention
> + *
> + * In order to avoid deadlock situations between dma-buf exports and importers,
> + * all dma-buf API users must follow the common dma-buf locking convention.
> + *
> + * Convention for importers
> + *
> + * 1. Importers must hold the dma-buf reservation lock when calling these
> + * functions:
> + *
> + * - dma_buf_pin()
> + * - dma_buf_unpin()
> + * - dma_buf_map_attachment()
> + * - dma_buf_unmap_attachment()
> + * - dma_buf_vmap()
> + * - dma_buf_vunmap()
> + *
> + * 2. Importers must not hold the dma-buf reservation lock when calling these
> + * functions:
> + *
> + * - dma_buf_attach()
> + * - dma_buf_dynamic_attach()
> + * - dma_buf_detach()
> + * - dma_buf_export(
> + * - dma_buf_fd()
> + * - dma_buf_get()
> + * - dma_buf_put()
> + * - dma_buf_mmap()
> + * - dma_buf_begin_cpu_access()
> + * - dma_buf_end_cpu_access()
> + * - dma_buf_map_attachment_unlocked()
> + * - dma_buf_unmap_attachment_unlocked()
> + * - dma_buf_vmap_unlocked()
> + * - dma_buf_vunmap_unlocked()
> + *
> + * Convention for exporters
> + *
> + * 1. These &dma_buf_ops callbacks are invoked with unlocked dma-buf
> + * reservation and exporter can take the lock:
> + *
> + * - &dma_buf_ops.attach()
> + * - &dma_buf_ops.detach()
> + * - &dma_buf_ops.release()
> + * - &dma_buf_ops.begin_cpu_access()
> + * - &dma_buf_ops.end_cpu_access()
> + *
> + * 2. These &dma_buf_ops callbacks are invoked with locked dma-buf
> + * reservation and exporter can't take the lock:
> + *
> + * - &dma_buf_ops.pin()
> + * - &dma_buf_ops.unpin()
> + * - &dma_buf_ops.map_dma_buf()
> + * - &dma_buf_ops.unmap_dma_buf()
> + * - &dma_buf_ops.mmap()
> + * - &dma_buf_ops.vmap()
> + * - &dma_buf_ops.vunmap()
> + *
> + * 3. Exporters must hold the dma-buf reservation lock when calling these
> + * functions:
> + *
> + * - dma_buf_move_notify()
> + */
> +
> /**
> * dma_buf_dynamic_attach - Add the device to dma_buf's attachments list
> * @dmabuf: [in] buffer to attach device to.
Powered by blists - more mailing lists