[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8adef36a-1f35-e8df-3b7b-2f994a204be1@vmware.com>
Date: Tue, 12 May 2020 02:19:25 +0200
From: Roland Scheidegger <sroland@...are.com>
To: Marek Szyprowski <m.szyprowski@...sung.com>,
<dri-devel@...ts.freedesktop.org>,
<iommu@...ts.linux-foundation.org>,
<linaro-mm-sig@...ts.linaro.org>, <linux-kernel@...r.kernel.org>
CC: Bartlomiej Zolnierkiewicz <b.zolnierkie@...sung.com>,
Airlie <airlied@...ux.ie>,
VMware Graphics <linux-graphics-maintainer@...are.com>,
Daniel Vetter <daniel@...ll.ch>,
Robin Murphy <robin.murphy@....com>,
Christoph Hellwig <hch@....de>,
<linux-arm-kernel@...ts.infradead.org>
Subject: Re: [Linux-graphics-maintainer] [PATCH v3 15/25] drm: vmwgfx: fix
common struct sg_table related issues
I'm not exactly an expert on this, but looks alright to me.
Acked-by: Roland Scheidegger <sroland@...are.com>
Am 05.05.20 um 10:46 schrieb Marek Szyprowski:
> The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the
> numer of the created entries in the DMA address space. However the
> subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be
> called with the original number of the entries passed to dma_map_sg. The
> sg_table->nents in turn holds the result of the dma_map_sg call as stated
> in include/linux/scatterlist.h. A common mistake was to ignore a result
> of the dma_map_sg function and don't use the sg_table->orig_nents at all.
>
> To avoid such issues, lets use common dma-mapping wrappers operating
> directly on the struct sg_table objects and adjust references to the
> nents and orig_nents respectively.
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@...sung.com>
> ---
> For more information, see '[PATCH v3 00/25] DRM: fix struct sg_table nents
> vs. orig_nents misuse' thread: https://lkml.org/lkml/2020/5/5/187
> ---
> drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 17 ++++-------------
> 1 file changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> index bf0bc46..e50ae8b 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> @@ -362,8 +362,7 @@ static void vmw_ttm_unmap_from_dma(struct vmw_ttm_tt *vmw_tt)
> {
> struct device *dev = vmw_tt->dev_priv->dev->dev;
>
> - dma_unmap_sg(dev, vmw_tt->sgt.sgl, vmw_tt->sgt.nents,
> - DMA_BIDIRECTIONAL);
> + dma_unmap_sgtable(dev, vmw_tt->sgt, DMA_BIDIRECTIONAL);
> vmw_tt->sgt.nents = vmw_tt->sgt.orig_nents;
> }
>
> @@ -383,16 +382,8 @@ static void vmw_ttm_unmap_from_dma(struct vmw_ttm_tt *vmw_tt)
> static int vmw_ttm_map_for_dma(struct vmw_ttm_tt *vmw_tt)
> {
> struct device *dev = vmw_tt->dev_priv->dev->dev;
> - int ret;
> -
> - ret = dma_map_sg(dev, vmw_tt->sgt.sgl, vmw_tt->sgt.orig_nents,
> - DMA_BIDIRECTIONAL);
> - if (unlikely(ret == 0))
> - return -ENOMEM;
>
> - vmw_tt->sgt.nents = ret;
> -
> - return 0;
> + return dma_map_sgtable(dev, vmw_tt->sgt, DMA_BIDIRECTIONAL);
> }
>
> /**
> @@ -449,10 +440,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
> if (unlikely(ret != 0))
> goto out_sg_alloc_fail;
>
> - if (vsgt->num_pages > vmw_tt->sgt.nents) {
> + if (vsgt->num_pages > vmw_tt->sgt.orig_nents) {
> uint64_t over_alloc =
> sgl_size * (vsgt->num_pages -
> - vmw_tt->sgt.nents);
> + vmw_tt->sgt.orig_nents);
>
> ttm_mem_global_free(glob, over_alloc);
> vmw_tt->sg_alloc_size -= over_alloc;
>
Powered by blists - more mailing lists