Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1375728ybb; Sun, 29 Mar 2020 03:06:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt4RVEAAdFshSOHVIJFhjqkPnX/m4Nd/TmRqbVzwwnwdn5/zoRe1xBACG33lw15R//ovWZL X-Received: by 2002:a9d:d0f:: with SMTP id 15mr5552753oti.161.1585476405068; Sun, 29 Mar 2020 03:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585476405; cv=none; d=google.com; s=arc-20160816; b=GQnDeqikMNq2TIV7lP5EVdBE0KdDHBwNbCanCo1swdveWYg6/3GZf9JLYJilNiV4Ck 7p9rXlI5MBjZpkoE5PXxw+s8Rx8ra8aWLUvGQt62h4b514/90w5HKzAyrFei/O9vg+Ad MIHLiZ5SumbZVrPm9osF0dy2JeJoIf+nV/kXpGkaGGkaDtRKiL4zZ0X39cKFXWSmfgBQ M8X3qPn8RCtzfvWcNeXUCRVLzS1h+7McTEQAf3c6j/NW/H1sxWUKEaZsJbpt4gY8Bx0h Hi4l62slRJLAK6wq/8zYZ63x9DQp3oXcdyw3uw8RQ2R7StE2Vh/e8kW55WthmpIz6hyt cL6w== 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=ZE/8RPCzXsNKOub72kPPybyFco+1U8wUJ08oc7Pxotc=; b=k3k11+tj9Fs4kKiw7Q2+0oZ6OmVWFoDZijQMg4vcRuxOyijTWapJu/OsqB2DvuxXeB /dESVGkqjeVKc/hdUbTCdYtg6qoeI0EseMiWvdOZZfQ8PyA8520+Ay6vAV1H0qrTwxPF nuH8umt29HM5WovpS7debA7HYjZvOkVY0Cq9P38kIgSC3yG2fBOuJHpp/GqmXt3SM6HX khgBBSFGTEqsaI6VF5wjvnyLjLA/3iLgA6upqt3PxrB7Ar7Nfr6X6jc16iJdaSVYHl2d /GO4uFaIvKOfzmZHf3cGQXc+JF5HC+Z8LtX4yVc+0M0c7w0E4lN+WbZPBJa/jqjBAsxO AhCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=bWBcgspM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id h1si4546751otr.127.2020.03.29.03.06.29; Sun, 29 Mar 2020 03:06:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=bWBcgspM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727902AbgC2Jz7 (ORCPT + 99 others); Sun, 29 Mar 2020 05:55:59 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:52895 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727828AbgC2Jz6 (ORCPT ); Sun, 29 Mar 2020 05:55:58 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200329095555euoutp01164243b337835a9640e49d83ece273e4~AvcyrZx4X2544025440euoutp01V for ; Sun, 29 Mar 2020 09:55:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200329095555euoutp01164243b337835a9640e49d83ece273e4~AvcyrZx4X2544025440euoutp01V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1585475755; bh=ZE/8RPCzXsNKOub72kPPybyFco+1U8wUJ08oc7Pxotc=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=bWBcgspMolpapA2FIPkBywqcySqyokj9lx2m1Ya71GO8I80yNVv2lvjwmS9CZaew5 MQ9THwdjlTaLsP3iFEVWwjisXhlS/Y5+QYyOTDzs4Gn5pX3SUvD2AsaSGqQAjWDGHB 9Hm2oOEFFqdaKlMtFZAiZHS0wKKTD2I2Vqz2EzLw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200329095555eucas1p2b56dc2cdb4c4e2a30541b88a186b6f5a~AvcyRlgA82895928959eucas1p21; Sun, 29 Mar 2020 09:55:55 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id C2.1A.60698.AA0708E5; Sun, 29 Mar 2020 10:55:55 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200329095554eucas1p2153edb2d11e85bb092aea8562a9357d5~AvcxlcMzH1913719137eucas1p2F; Sun, 29 Mar 2020 09:55:54 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200329095554eusmtrp14d379a191ac3af5df37b5a5e6c8ed976~AvcxkwYM82129621296eusmtrp14; Sun, 29 Mar 2020 09:55:54 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-6b-5e8070aa4035 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 7A.A2.08375.AA0708E5; Sun, 29 Mar 2020 10:55:54 +0100 (BST) Received: from [106.210.88.143] (unknown [106.210.88.143]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200329095553eusmtip2904d1afdb45fd775b0d195520eb39bae~Avcwz3tQu0515205152eusmtip2U; Sun, 29 Mar 2020 09:55:53 +0000 (GMT) Subject: Re: [PATCH v2] drm/prime: fix extracting of the DMA addresses from a scatterlist To: "Ruhl, Michael J" , "dri-devel@lists.freedesktop.org" , "linux-samsung-soc@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: "stable@vger.kernel.org" , Bartlomiej Zolnierkiewicz , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Alex Deucher , Shane Francis From: Marek Szyprowski Message-ID: <8a09916d-5413-f9a8-bafa-2d8f0b8f892f@samsung.com> Date: Sun, 29 Mar 2020 11:55:45 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <14063C7AD467DE4B82DEDB5C278E8663FFFBFCE1@fmsmsx107.amr.corp.intel.com> Content-Transfer-Encoding: 7bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA02SfyyUcRzH+z7Pc889TqfH0XymUl1pY0uMrWdlytbaU39UVv+Eri6e0eLY naOrtsiPuJRkQ5eF2tCVMxzyIxuaI0VS+iWia/Irs8OWUN09/fDf5/39vD7vz+e9fSlcYha4 UmcUcZxSIY+SkiKitv17z/YHsYky74lSxFzr7sSY3IFGAVOZXyFgkuqvY8zP2myceTU3TTJ9 DQUkk9/TjDHFMzUE86LOk0nLKBEwRZUjiDFOZgv2itnUl0sk+3i+iGDrdR+F7L2mMYyt0meQ bN38JwF7pzOIHbpqwtjrRj1iq7susJYqtyP2wSL/cC7qTDyn3BFwShRpWRokYi1bz9Vo27BE dN9NiygKaD8o7knQIhElocsQFLZMCnkxi+DJQjLBCwuCpucVpBbZ2SZyk1JxvlGK4M2SFuPF NALDazNmpZzoEBhYM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gE7iVktc1hAbBYBVYnPf9+wg9iiAjESP/d0sUDUCEqcnPkE zOYUCJE4dn8dWA2zgJnEvM0PmSFseYntb+dA2eISt57MZ5rAKDQLSfssJC2zkLTMQtKygJFl FaNIamlxbnpusaFecWJucWleul5yfu4mRmC0bzv2c/MOxksbgw8xCnAwKvHwGlTWxwmxJpYV V+YeYpTgYFYS4WXzb4gT4k1JrKxKLcqPLyrNSS0+xGgK9NxEZinR5HxgIsoriTc0NTS3sDQ0 NzY3NrNQEuftEDgYIySQnliSmp2aWpBaBNPHxMEp1cDoHpG78GBamta32yVpmw1ePtp3KpbD R73/wKfDTjm2GfXHc6KkJ0177yz2Qlqt9mPZ/p+yzr0xq06/Ke6vspY6ea59llbV55a9Au0M bTsSDW0tVx8MmxHRvaTGQU5uR9a0P0fThdV239m9ptLakVm644jJ6SW3K88qLYhefXH5BgnT Wvlfk72UWIozEg21mIuKEwErd8d6DAMAAA== X-CMS-MailID: 20200329095554eucas1p2153edb2d11e85bb092aea8562a9357d5 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200327162330eucas1p1b0413e0e9887aa76d3048f86d2166dcd X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200327162330eucas1p1b0413e0e9887aa76d3048f86d2166dcd References: <20200327162126.29705-1-m.szyprowski@samsung.com> <14063C7AD467DE4B82DEDB5C278E8663FFFBFCE1@fmsmsx107.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 2020-03-27 19:31, Ruhl, Michael J wrote: >> -----Original Message----- >> From: Marek Szyprowski >> Sent: Friday, March 27, 2020 12:21 PM >> To: dri-devel@lists.freedesktop.org; linux-samsung-soc@vger.kernel.org; >> linux-kernel@vger.kernel.org >> Cc: Marek Szyprowski ; >> stable@vger.kernel.org; Bartlomiej Zolnierkiewicz >> ; Maarten Lankhorst >> ; Maxime Ripard >> ; Thomas Zimmermann ; >> David Airlie ; Daniel Vetter ; Alex Deucher >> ; Shane Francis ; >> Ruhl, Michael J >> Subject: [PATCH v2] drm/prime: fix extracting of the DMA addresses from a >> scatterlist >> >> Scatterlist elements contains both pages and DMA addresses, but one >> should not assume 1:1 relation between them. The sg->length is the size >> of the physical memory chunk described by the sg->page, while >> sg_dma_len(sg) is the size of the DMA (IO virtual) chunk described by >> the sg_dma_address(sg). >> >> The proper way of extracting both: pages and DMA addresses of the whole >> buffer described by a scatterlist it to iterate independently over the >> sg->pages/sg->length and sg_dma_address(sg)/sg_dma_len(sg) entries. >> >> Fixes: 42e67b479eab ("drm/prime: use dma length macro when mapping sg") >> Signed-off-by: Marek Szyprowski >> Reviewed-by: Alex Deucher >> --- >> drivers/gpu/drm/drm_prime.c | 37 +++++++++++++++++++++++++----------- >> - >> 1 file changed, 25 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c >> index 1de2cde2277c..282774e469ac 100644 >> --- a/drivers/gpu/drm/drm_prime.c >> +++ b/drivers/gpu/drm/drm_prime.c >> @@ -962,27 +962,40 @@ int drm_prime_sg_to_page_addr_arrays(struct >> sg_table *sgt, struct page **pages, >> unsigned count; >> struct scatterlist *sg; >> struct page *page; >> - u32 len, index; >> + u32 page_len, page_index; >> dma_addr_t addr; >> + u32 dma_len, dma_index; >> >> - index = 0; >> + /* >> + * Scatterlist elements contains both pages and DMA addresses, but >> + * one shoud not assume 1:1 relation between them. The sg->length >> is >> + * the size of the physical memory chunk described by the sg->page, >> + * while sg_dma_len(sg) is the size of the DMA (IO virtual) chunk >> + * described by the sg_dma_address(sg). >> + */ > Is there an example of what the scatterlist would look like in this case? DMA framework or IOMMU is allowed to join consecutive chunks while mapping if such operation is supported by the hw. Here is the example: Lets assume that we have a scatterlist with 4 4KiB pages of the physical addresses: 0x12000000, 0x13011000, 0x13012000, 0x11011000. The total size of the buffer is 16KiB. After mapping this scatterlist to a device behind an IOMMU it may end up as a contiguous buffer in the DMA (IOVA) address space. at 0xf0010000. The scatterlist will look like this: sg[0].page = 0x12000000 sg[0].len = 4096 sg[0].dma_addr = 0xf0010000 sg[0].dma_len = 16384 sg[1].page = 0x13011000 sg[1].len = 4096 sg[1].dma_addr = 0 sg[1].dma_len = 0 sg[2].page = 0x13012000 sg[2].len = 4096 sg[2].dma_addr = 0 sg[2].dma_len = 0 sg[3].page = 0x11011000 sg[3].len = 4096 sg[3].dma_addr = 0 sg[3].dma_len = 0 (I've intentionally wrote page as physical address to make it easier to understand, in real SGs it is stored a struct page pointer). > Does each SG entry always have the page and dma info? or could you have > entries that have page information only, and entries that have dma info only? When SG is not mapped yet it contains only the ->pages and ->len entries. I'm not aware of the SGs with the DMA information only, but in theory it might be possible to have such. > If the same entry has different size info (page_len = PAGE_SIZE, > dma_len = 4 * PAGE_SIZE?), are we guaranteed that the arrays (page and addrs) have > been sized correctly? There are always no more DMA related entries than the phys pages. If there is 1:1 mapping between physical memory and DMA (IOVA) space, then each SG entry will have len == dma_len, and dma_addr will be describing the same as page entry. DMA mapping framework is allowed only to join entries while mapping to DMA (IOVA). > Just trying to get my head wrapped around this. Sure, I hope my explanation helps a bit. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland