From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 333E6C433E1 for ; Fri, 19 Jun 2020 09:43:57 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0379320890 for ; Fri, 19 Jun 2020 09:43:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0379320890 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id CEDE787692; Fri, 19 Jun 2020 09:43:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0kqBJJeUGrDX; Fri, 19 Jun 2020 09:43:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1377286F14; Fri, 19 Jun 2020 09:43:54 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E7256C07FF; Fri, 19 Jun 2020 09:43:53 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id CE69EC016E for ; Fri, 19 Jun 2020 09:43:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id C725B2039C for ; Fri, 19 Jun 2020 09:43:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1fWE8d1M26Q9 for ; Fri, 19 Jun 2020 09:43:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by silver.osuosl.org (Postfix) with ESMTP id 355EA20020 for ; Fri, 19 Jun 2020 09:43:50 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6D1392B; Fri, 19 Jun 2020 02:43:49 -0700 (PDT) Received: from [10.57.9.128] (unknown [10.57.9.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5BE7C3F71F; Fri, 19 Jun 2020 02:43:47 -0700 (PDT) Subject: Re: [PATCH v6 35/36] videobuf2: use sgtable-based scatterlist wrappers To: Marek Szyprowski , dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org References: <20200618153956.29558-1-m.szyprowski@samsung.com> <20200618153956.29558-36-m.szyprowski@samsung.com> From: Robin Murphy Message-ID: Date: Fri, 19 Jun 2020 10:43:46 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200618153956.29558-36-m.szyprowski@samsung.com> Content-Language: en-GB Cc: Pawel Osciak , Bartlomiej Zolnierkiewicz , David Airlie , Daniel Vetter , Hans Verkuil , Mauro Carvalho Chehab , Christoph Hellwig , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On 2020-06-18 16:39, Marek Szyprowski wrote: > Use recently introduced common wrappers operating directly on the struct > sg_table objects and scatterlist page iterators to make the code a bit > more compact, robust, easier to follow and copy/paste safe. > > No functional change, because the code already properly did all the > scaterlist related calls. > > Signed-off-by: Marek Szyprowski > --- > .../common/videobuf2/videobuf2-dma-contig.c | 41 ++++++++----------- > .../media/common/videobuf2/videobuf2-dma-sg.c | 32 ++++++--------- > .../common/videobuf2/videobuf2-vmalloc.c | 12 ++---- > 3 files changed, 34 insertions(+), 51 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c > index f4b4a7c135eb..ba01a8692d88 100644 > --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c > +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c > @@ -48,16 +48,15 @@ struct vb2_dc_buf { > > static unsigned long vb2_dc_get_contiguous_size(struct sg_table *sgt) > { > - struct scatterlist *s; > dma_addr_t expected = sg_dma_address(sgt->sgl); > - unsigned int i; > + struct sg_dma_page_iter dma_iter; > unsigned long size = 0; > > - for_each_sg(sgt->sgl, s, sgt->nents, i) { > - if (sg_dma_address(s) != expected) > + for_each_sgtable_dma_page(sgt, &dma_iter, 0) { > + if (sg_page_iter_dma_address(&dma_iter) != expected) > break; > - expected = sg_dma_address(s) + sg_dma_len(s); > - size += sg_dma_len(s); > + expected += PAGE_SIZE; > + size += PAGE_SIZE; Same comment as for the DRM version. In fact, given that it's the same function with the same purpose, might it be worth hoisting out as a generic helper for the sg_table API itself? > } > return size; > } [...] > diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c > index 92072a08af25..6ddf953efa11 100644 > --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c > +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c > @@ -142,9 +142,8 @@ static void *vb2_dma_sg_alloc(struct device *dev, unsigned long dma_attrs, > * No need to sync to the device, this will happen later when the > * prepare() memop is called. > */ > - sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, > - buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC); > - if (!sgt->nents) > + if (dma_map_sgtable(buf->dev, sgt, buf->dma_dir, > + DMA_ATTR_SKIP_CPU_SYNC)) { As 0-day's explosions of nonsense imply, there's a rogue bracket here... > goto fail_map; > > buf->handler.refcount = &buf->refcount; > @@ -180,8 +179,8 @@ static void vb2_dma_sg_put(void *buf_priv) > if (refcount_dec_and_test(&buf->refcount)) { > dprintk(1, "%s: Freeing buffer of %d pages\n", __func__, > buf->num_pages); > - dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, > - buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC); > + dma_unmap_sgtable(buf->dev, sgt, buf->dma_dir, > + DMA_ATTR_SKIP_CPU_SYNC); > if (buf->vaddr) > vm_unmap_ram(buf->vaddr, buf->num_pages); > sg_free_table(buf->dma_sgt); > @@ -202,8 +201,7 @@ static void vb2_dma_sg_prepare(void *buf_priv) > if (buf->db_attach) > return; > > - dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, > - buf->dma_dir); > + dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir); > } > > static void vb2_dma_sg_finish(void *buf_priv) > @@ -215,7 +213,7 @@ static void vb2_dma_sg_finish(void *buf_priv) > if (buf->db_attach) > return; > > - dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); > + dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir); > } > > static void *vb2_dma_sg_get_userptr(struct device *dev, unsigned long vaddr, > @@ -258,9 +256,8 @@ static void *vb2_dma_sg_get_userptr(struct device *dev, unsigned long vaddr, > * No need to sync to the device, this will happen later when the > * prepare() memop is called. > */ > - sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, > - buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC); > - if (!sgt->nents) > + if (dma_map_sgtable(buf->dev, sgt, buf->dma_dir, > + DMA_ATTR_SKIP_CPU_SYNC)) { ... and here. Robin. _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu