Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2254ybk; Tue, 12 May 2020 13:35:49 -0700 (PDT) X-Google-Smtp-Source: APiQypIEg2I9jSDZ9x5S2t9AV8LZ+tQ+u38bupjWuuqS7xqHub8WcwA1B4wNnN3j3ZmWVNL3z37v X-Received: by 2002:a17:906:cf8a:: with SMTP id um10mr19003487ejb.60.1589315749591; Tue, 12 May 2020 13:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589315749; cv=none; d=google.com; s=arc-20160816; b=0Ne07JjHUAKcB6XlxGoUBFiz0vmDojQvJ6AA4OKfvHixVRZOrmucgiLqRSPVgTPukp 44DWGO9iB2HHeJfK5cWxOF9vm2jmUZoC7vtQJA3w19nR4C7xTXmYVnQmKlv+6xzDfbi1 MN0oSvQCVBImP9SUEFtVHM4fx2ow4B0BhfJGfmWeGpVd6enFwsfTEyhZ0ObjnKBzwU9p v3pUloPXlNmb09a/Qo2j/JpCGxOXZuRRe+SI58okd/pynEkx1ONknCDAyqkJpgEisRVU +DVhhrq0GmhgQcl80G5HzBFu/TeL4uTh9xhntmjtlc0ppNhLL1AbvIrZhaJNuCJqG0br MKMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:subject:dkim-signature:dkim-filter; bh=wnAc6t9J+MLeu4DXX/UMTG7FIxfuzBk4sujw+pbXYuI=; b=dp+19LDcK4oydEa78jEQ9ZMRQxwvQrUU3OHQPjy6Y8GlzARnbk6nu5GX+Ps1rh+pxa 5FlcLuHV7cauYSY9eBzWErI5szBQ+lmHUni45Yu49xkDy6Bpvyax6ro5gUdSqzp/irDZ j6Ww08SHaby9uJpnGFBAGNmOtVRAP9N9ztI0fWDnt4bwMqB3fZeSkiFwQsj9trmLWA+L pedo6V7ExOVvaFvSDtxDDHTClpn7OHTP1xX6ShFkGMk7+Xyz++dX4DG6G3B8ZWOPUtSc om+bd31L6Pf2SovqUfoIhZ90mIhENVdF6tC9L8l/ew7NIPHj7ow/pa56WXBKZrUH/PBN DiVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=vFcP7z7i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a42si8724737edf.186.2020.05.12.13.35.26; Tue, 12 May 2020 13:35:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=vFcP7z7i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729619AbgELUd6 (ORCPT + 99 others); Tue, 12 May 2020 16:33:58 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:50702 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725950AbgELUd5 (ORCPT ); Tue, 12 May 2020 16:33:57 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200512203355euoutp02706617157b883cf9c5002f2710f61d99~OYiZVzkDE2274122741euoutp02H for ; Tue, 12 May 2020 20:33:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200512203355euoutp02706617157b883cf9c5002f2710f61d99~OYiZVzkDE2274122741euoutp02H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1589315635; bh=wnAc6t9J+MLeu4DXX/UMTG7FIxfuzBk4sujw+pbXYuI=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=vFcP7z7iNFqcPY/EoZ5ceEWyjH1xwGyPTsFs44xdrk9/usQK/cCqb6wNTikhe/cz3 VRuU1QMd4IzJN8gNMfXAO/FSr7WAEwp3UEQA958LHOtJuBsPdJUyXn7cor0p/GkEeY qrecZ9OJZgAZ759EqpgSB1rwj676W+1IKU9G/b1E= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200512203354eucas1p1ccad241d082e172806147e8051ca5cd5~OYiY_s_Nd1765817658eucas1p1P; Tue, 12 May 2020 20:33:54 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 59.BC.60679.2380BBE5; Tue, 12 May 2020 21:33:54 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200512203354eucas1p1ec0713551239b5437374232a3558db8e~OYiYXwwvs1766317663eucas1p1P; Tue, 12 May 2020 20:33:54 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200512203354eusmtrp29c5130625112f643794304998f69d654~OYiYXBRxv1599815998eusmtrp2e; Tue, 12 May 2020 20:33:54 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-4a-5ebb08320b1c Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id C1.CA.07950.2380BBE5; Tue, 12 May 2020 21:33:54 +0100 (BST) Received: from [106.210.88.143] (unknown [106.210.88.143]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200512203353eusmtip24e27fc61e27b356e67372df3a9c99d61~OYiXny--L2981929819eusmtip2U; Tue, 12 May 2020 20:33:53 +0000 (GMT) Subject: Re: [PATCH v4 38/38] videobuf2: use sgtable-based scatterlist wrappers To: "Ruhl, Michael J" , "dri-devel@lists.freedesktop.org" , "iommu@lists.linux-foundation.org" , "linaro-mm-sig@lists.linaro.org" , "linux-kernel@vger.kernel.org" Cc: Pawel Osciak , Bartlomiej Zolnierkiewicz , David Airlie , "linux-media@vger.kernel.org" , Hans Verkuil , Mauro Carvalho Chehab , Robin Murphy , Christoph Hellwig , "linux-arm-kernel@lists.infradead.org" From: Marek Szyprowski Message-ID: Date: Tue, 12 May 2020 22:33:54 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <14063C7AD467DE4B82DEDB5C278E8663010E210FAC@FMSMSX108.amr.corp.intel.com> Content-Transfer-Encoding: 7bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA01SfyyUcRzu+773vveSs9fRfCax3cqWLUVt3k2MVdvbVqv80aaNOnmHdYfu TaoxJpOOykjpRpRWuejH3XGclu6K82NJkemHJP4hxjiWH5HzUv57nufzfPY8n+1D4dJpwoOK TzjHqRLkChnpKKptnu3YEUA1RO1qMQUw1zpaMeZF8TOC6Z4eJ5nKJ00Y8+FOn4gpbwxibN0D GKMb7CGYLlMJyeQ9ryGYh7oFjOk0+jI3x2bFjHliiAh1ZqvuViG24uUwxuq0V0nWOPODYPtz rRirf5DOfl0cxNnC3keIbficQbKDc8Mke92gReyUzottm54SH5WccNwbwyniz3OqnSGnHONs 83lYUrbnheq+ESwD9burkQMF9B54YnlLqJEjJaUfIzCPvhELxIbgxuRTkUCmEEzO3EZrK9nW biQMHiH4dGUeE8g4glaDHre7XOljMJKlwe0DN7oZg/HK+pUUnK7CYWEhR2x3kbQ/qMfUpB1L 6BBo1WZidiyit8FMft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LoYOTg4BcIk5h5XAQkzC5hJzNv8kBnClpfY/nYOlC0ucevJfKYJ jEKzkHTPQtIyC0nLLCQtCxhZVjGKpJYW56bnFhvpFSfmFpfmpesl5+duYgQmgm3Hfm7Zwdj1 LvgQowAHoxIPb0T9rjgh1sSy4srcQ4wSHMxKIrwtmTvjhHhTEiurUovy44tKc1KLDzGaAv02 kVlKNDkfmKTySuINTQ3NLSwNzY3Njc0slMR5OwQOxggJpCeWpGanphakFsH0MXFwSjUwNm3l /NjmYWpvPWe3RtE5l5/PXaMSlHe8Phi5QIVHqIbh8jrPgDxGLr6C913Plnx3yQl9VauyYyHj D+bN7+Zt4F0qO1H1z4pGNb22+tTbRpzzV06dp7Zg+96NE668PJztt8Vc6/qyzusMWU97LRbc vf1BI87IPinqQOMTUfld7lxpaddntH+bocRSnJFoqMVcVJwIAH0Po9kaAwAA X-CMS-MailID: 20200512203354eucas1p1ec0713551239b5437374232a3558db8e X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200512090130eucas1p2eb86c5d34be56bbc81032bc0b6927d1e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200512090130eucas1p2eb86c5d34be56bbc81032bc0b6927d1e References: <20200512085710.14688-1-m.szyprowski@samsung.com> <20200512090058.14910-1-m.szyprowski@samsung.com> <20200512090058.14910-38-m.szyprowski@samsung.com> <14063C7AD467DE4B82DEDB5C278E8663010E210FAC@FMSMSX108.amr.corp.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, On 12.05.2020 19:52, Ruhl, Michael J wrote: >> -----Original Message----- >> From: dri-devel On Behalf Of >> Marek Szyprowski >> Sent: Tuesday, May 12, 2020 5:01 AM >> To: dri-devel@lists.freedesktop.org; iommu@lists.linux-foundation.org; >> linaro-mm-sig@lists.linaro.org; linux-kernel@vger.kernel.org >> Cc: Pawel Osciak ; Bartlomiej Zolnierkiewicz >> ; David Airlie ; linux- >> media@vger.kernel.org; Hans Verkuil ; Mauro >> Carvalho Chehab ; Robin Murphy >> ; Christoph Hellwig ; linux-arm- >> kernel@lists.infradead.org; Marek Szyprowski >> >> Subject: [PATCH v4 38/38] videobuf2: use sgtable-based scatterlist wrappers >> >> 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 >> --- >> For more information, see '[PATCH v4 00/38] DRM: fix struct sg_table nents >> vs. orig_nents misuse' thread: >> https://lore.kernel.org/dri-devel/20200512085710.14688-1- >> m.szyprowski@samsung.com/T/ >> --- >> .../media/common/videobuf2/videobuf2-dma-contig.c | 41 ++++++++++---- >> -------- >> drivers/media/common/videobuf2/videobuf2-dma-sg.c | 32 +++++++-------- >> -- >> drivers/media/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 d3a3ee5..bf31a9d 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; > This code in drm_prime_t_contiguous_size and here. I seem to remember seeing > the same pattern in other drivers. > > Would it worthwhile to make this a helper as well? I think I've identified such patterns in all DRM drivers and replaced with a common helper. So far I have no idea where to put such helper to make it available for media/videobuf2, so those a few lines are indeed duplicated here. > Also, isn't the sg_dma_len() the actual length of the chunk we are looking at? > > If its I not PAGE_SIZE (ie. dma chunk is 4 * PAGE_SIZE?), does your loop/calculation still work? scaterlist page iterators (for_each_sg_page/for_each_sg_dma_page and their sgtable variants) always operates on PAGE_SIZE units. They correctly handle larger sg_dma_len(). Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland