From: Daniel Vetter <daniel@ffwll.ch>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 03/12] dma-buf: start caching of sg_table objects
Date: Mon, 29 Apr 2019 10:54:55 +0200 [thread overview]
Message-ID: <20190429085455.GN3271@phenom.ffwll.local> (raw)
In-Reply-To: <20190426123638.40221-3-christian.koenig@amd.com>
On Fri, Apr 26, 2019 at 02:36:29PM +0200, Christian König wrote:
> To allow a smooth transition from pinning buffer objects to dynamic
> invalidation we first start to cache the sg_table for an attachment
> unless the driver has implemented the explicite pin/unpin callbacks.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
Correction on my "squash everything" suggestion: I think this patch here
still needs to be separate, so that "why did this cause a regression" is
easier to understand. But with a small nit.
> ---
> drivers/dma-buf/dma-buf.c | 24 ++++++++++++++++++++++++
> include/linux/dma-buf.h | 1 +
> 2 files changed, 25 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 0656dcf289be..a18d10c4425a 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -610,6 +610,20 @@ dma_buf_attach(const struct dma_buf_attach_info *info)
> list_add(&attach->node, &dmabuf->attachments);
>
> mutex_unlock(&dmabuf->lock);
> +
> + if (!dmabuf->ops->pin) {
I think a static inline dma_buf_is_dynamic_attachment() would be good
here, which in this patch (since it's ealier) would always return false.
Aside: I think only checking pin here (i.e. can the exporter do dynamic
mappings) isn't good enough, we also need to check for the importers
->invalidate. Hence _is_dynamic_attachment, not _is_dynamic_dma_buf. If we
don't also check for the importer we again have a reservation lock in
dma_buf_map/unmap, which we know will anger the lockdep gods ...
-Daniel
> + struct sg_table *sgt;
> +
> + sgt = dmabuf->ops->map_dma_buf(attach, DMA_BIDIRECTIONAL);
> + if (!sgt)
> + sgt = ERR_PTR(-ENOMEM);
> + if (IS_ERR(sgt)) {
> + dma_buf_detach(dmabuf, attach);
> + return ERR_CAST(sgt);
> + }
> + attach->sgt = sgt;
> + }
> +
> return attach;
>
> err_attach:
> @@ -632,6 +646,10 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
> if (WARN_ON(!dmabuf || !attach))
> return;
>
> + if (attach->sgt)
> + dmabuf->ops->unmap_dma_buf(attach, attach->sgt,
> + DMA_BIDIRECTIONAL);
> +
> mutex_lock(&dmabuf->lock);
> list_del(&attach->node);
> if (dmabuf->ops->detach)
> @@ -668,6 +686,9 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
> if (WARN_ON(!attach || !attach->dmabuf))
> return ERR_PTR(-EINVAL);
>
> + if (attach->sgt)
> + return attach->sgt;
> +
> reservation_object_lock(attach->dmabuf->resv, NULL);
> r = dma_buf_pin(attach->dmabuf);
> reservation_object_unlock(attach->dmabuf->resv);
> @@ -701,6 +722,9 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
> if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
> return;
>
> + if (attach->sgt == sg_table)
> + return;
> +
> attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
> direction);
>
> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> index 0321939b1c3d..b9d0719581cd 100644
> --- a/include/linux/dma-buf.h
> +++ b/include/linux/dma-buf.h
> @@ -345,6 +345,7 @@ struct dma_buf_attachment {
> struct dma_buf *dmabuf;
> struct device *dev;
> struct list_head node;
> + struct sg_table *sgt;
> void *priv;
> };
>
> --
> 2.17.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-04-29 8:54 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-26 12:36 [PATCH 01/12] dma-buf: add struct dma_buf_attach_info Christian König
2019-04-26 12:36 ` [PATCH 02/12] dma-buf: add explicit buffer pinning v2 Christian König
2019-04-29 8:40 ` Daniel Vetter
2019-04-30 13:42 ` Christian König
2019-04-30 13:59 ` Daniel Vetter
2019-04-30 14:26 ` Christian König
2019-04-30 14:34 ` Daniel Vetter
2019-04-30 14:41 ` Koenig, Christian
2019-04-30 15:22 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 03/12] dma-buf: start caching of sg_table objects Christian König
2019-04-29 8:54 ` Daniel Vetter [this message]
2019-04-30 14:18 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 04/12] dma-buf: lock the reservation object during (un)map_dma_buf v4 Christian König
2019-04-26 12:36 ` [PATCH 05/12] dma-buf: add dma_buf_(un)map_attachment_locked variants v4 Christian König
2019-04-26 12:36 ` [PATCH 06/12] dma-buf: add optional invalidate_mappings callback v5 Christian König
2019-04-29 8:42 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 07/12] drm: remove prime sg_table caching Christian König
2019-04-26 12:36 ` [PATCH 08/12] drm/ttm: remove the backing store if no placement is given Christian König
2019-04-26 12:36 ` [PATCH 09/12] drm/ttm: use the parent resv for ghost objects Christian König
2019-04-26 12:36 ` [PATCH 10/12] drm/amdgpu: add independent DMA-buf export v3 Christian König
2019-04-30 14:16 ` Daniel Vetter
2019-05-03 12:35 ` Christian König
2019-05-06 8:04 ` Daniel Vetter
2019-05-06 10:05 ` Koenig, Christian
2019-05-06 15:10 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 11/12] drm/amdgpu: add independent DMA-buf import v4 Christian König
2019-04-26 12:36 ` [PATCH 12/12] drm/amdgpu: add DMA-buf invalidation callback v2 Christian König
2019-04-29 8:24 ` [PATCH 01/12] dma-buf: add struct dma_buf_attach_info Daniel Vetter
2019-04-30 12:40 ` Christian König
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=20190429085455.GN3271@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
/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