From patchwork Fri Mar 27 16:21:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 185008 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp1494709ilr; Fri, 27 Mar 2020 09:23:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu6t3wbcrcZLGTbogsYnGZkpftd7kgC1JA3HcYHoKFJoKhW3nT8QNDwJdsKdfDJoxNNc5+X X-Received: by 2002:aa7:8643:: with SMTP id a3mr16096459pfo.133.1585326216046; Fri, 27 Mar 2020 09:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585326216; cv=none; d=google.com; s=arc-20160816; b=i0OgPPRRX81FZluDDt2dHEWCfrgDh0tXwIHUucHzyBjrI95mb/ldFr2ViqQ95KFbZL 1ARtV2htLaiYZgieu6WVdquUEoGkez7rQGMY7lEy71uBdh2vEsdZ05pRscZuqvd8JeGL f0jb/1J46PEAoIl62bPlbldn05/rPtNB5PVdoBSi2J5lImvrW5qFDpjAqYFuwC0IQeFt Gz1vr++Ob6v3ODxRoCPHatehBf2kI3CTFet/lA71nl3mMDP8f4hcBDsB4uXIhI4A1pxl y+pF7Ca8zoyR0TV24DUmRRAGnkkclBaR2OgFT+4aZV0pd48RvA2BB0lBdZDT4uTw5ff9 kxAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:cms-type:message-id:date:subject:to :from:dkim-signature:dkim-filter:delivered-to; bh=lEOq4apS25+63E/xkc9j9EBOll0/IhFfd3tfbh7pdr8=; b=KhsBGeHc6Hbq1/W8h8jdw/70kl6XBZ/7tQcPdm8S2Inh58p6GqyYzQ3fXTJ8luuLBU Mp9BB1x95yBWd2+nHuC4HFrC9CWC9Ee9ZenZjthkJZ5wqaHFwL5GDUmBzYm50CpL1jPu eSmm4fRzHk4dUCnIbgh4Tdo/Cx9vq0vOq/wvQVNDJFkPrxKKRBJduHB1U8vz0Ux1rB8H h97eFbYaudFcRlINaqAG8hkRBEmwMvOmeOWSWHBWschoslcHf7m0CKl4QpaMKzO8ZW4X qdzjZDdD4nnqpsg5e5eNztkBZpL1DOzLLPqL2K7bvrooKg5HxZu3llFadUX06bhsOnut B3/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=qlHuu19z; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id 10si4630803pll.258.2020.03.27.09.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 09:23:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=qlHuu19z; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8760F89D7C; Fri, 27 Mar 2020 16:23:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4300B89D7C for ; Fri, 27 Mar 2020 16:23:33 +0000 (UTC) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200327162331euoutp027b6f788641e43177153564799651d2ce~ANcpAk25e1169611696euoutp02a for ; Fri, 27 Mar 2020 16:23:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200327162331euoutp027b6f788641e43177153564799651d2ce~ANcpAk25e1169611696euoutp02a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1585326211; bh=FNcGHf3TErelyQyr0Jn7U9qXzR3Cb8ZHEa9kuu5TYeA=; h=From:To:Cc:Subject:Date:References:From; b=qlHuu19zdZeIrsu0DMoKtCl0dHgdmwwydb48UMvM0E89/FHlQVLAuFaI3ocz+MH2w huiwP0UImKHgwcTuwZgoHZVTbnx2AfGdWhzams0LXzvKh91WZBjzTk3Bq32BnhLCfu C/JwW3JWgUH0JO/GoEMhgmDfIC32SnKCPOJ624v4= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200327162330eucas1p248c9d4d771ddacebcd39c77c7d91e700~ANcoFYz_K3181231812eucas1p28; Fri, 27 Mar 2020 16:23:30 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id CD.5D.60679.2882E7E5; Fri, 27 Mar 2020 16:23:30 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200327162330eucas1p1b0413e0e9887aa76d3048f86d2166dcd~ANcnkxzW12015620156eucas1p1X; Fri, 27 Mar 2020 16:23:30 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200327162330eusmtrp1e3c051d09a2f3de797a2bf04d0500afc~ANcnj_tgS2160721607eusmtrp1_; Fri, 27 Mar 2020 16:23:30 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-b5-5e7e2882d3d4 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 86.9A.08375.1882E7E5; Fri, 27 Mar 2020 16:23:29 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200327162329eusmtip29f9109aa332277093a721501edfa2888~ANcm1vZUK2356123561eusmtip27; Fri, 27 Mar 2020 16:23:29 +0000 (GMT) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/prime: fix extracting of the DMA addresses from a scatterlist Date: Fri, 27 Mar 2020 17:21:26 +0100 Message-Id: <20200327162126.29705-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA0VSa0hTURzn3Neu5ux6FTpUGM7sbWZFnOhpFNwkwj5JgsulNw2dxpaWZuVm SWqJ2kNZIZtmvjJzrpkzrS1rDElLrSx6TXpZSc10pGS1eVd9+z35/Q8cGmcbydn0/tSDvCJV liKhvAnj/YneUPWiY9IVFlUQOtNjw9CFF+0kai5vIpGqrQhDv40lOBoY/0qhftMlCpX3dmKo seulCOkcNwj0sHUJysu/QiJt8xBAhi8l5GZf7mTfFMV1OLUE16Z5KeKqbg1jnL4+n+JanW9I rsK2i3tdaMW4IkM94Fq6j3Df9YFRM2K81yfwKfszeEXYxjjvpIomO3bgpv/h9nMfyRxgmlkA vGjIrIbvy2rIAuBNs0wtgG+6TB4yBqDurtpDvgPY26/G/lZM5l+UYNQA+GDKif2rDJZ8AO4U xYTDgpECV0pEBzD7YDXujuBMLw5fvTWL3BF/JhoWT6gpNyaYEF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owMGoxMO74mptnBBrYllxZe4hRgkOZiUR 3qeRNXFCvCmJlVWpRfnxRaU5qcWHGE2Blk9klhJNzgdGZ15JvKGpobmFpaG5sbmxmYWSOG+H wMEYIYH0xJLU7NTUgtQimD4mDk6pBkb+3PQfrksrrqzf5hCTwP/pyMfC+zOljruGC3Jv2pNg xC0an70g8eU0Q986+ejcCXE663ecUu6x/+liuTGxd698Xa4Ux/z1zMf8RRX2qLE2//0v3aSV WF/0ecXxdeanpZfrz1js9lVC2K/G6sneWU7bn/490LIhbaHJ9ZOPWzMUsvaaTTX//1mJpTgj 0VCLuag4EQCez0qLlgIAAA== X-CMS-MailID: 20200327162330eucas1p1b0413e0e9887aa76d3048f86d2166dcd X-Msg-Generator: CA X-RootMTR: 20200327162330eucas1p1b0413e0e9887aa76d3048f86d2166dcd X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200327162330eucas1p1b0413e0e9887aa76d3048f86d2166dcd References: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bartlomiej Zolnierkiewicz , David Airlie , Shane Francis , "Michael J . Ruhl" , stable@vger.kernel.org, Thomas Zimmermann , Alex Deucher , Marek Szyprowski MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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(-) -- 2.17.1 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel 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). + */ + page_index = 0; + dma_index = 0; for_each_sg(sgt->sgl, sg, sgt->nents, count) { - len = sg_dma_len(sg); + page_len = sg->length; page = sg_page(sg); + dma_len = sg_dma_len(sg); addr = sg_dma_address(sg); - while (len > 0) { - if (WARN_ON(index >= max_entries)) + while (pages && page_len > 0) { + if (WARN_ON(page_index >= max_entries)) return -1; - if (pages) - pages[index] = page; - if (addrs) - addrs[index] = addr; - + pages[page_index] = page; page++; + page_len -= PAGE_SIZE; + page_index++; + } + while (addrs && dma_len > 0) { + if (WARN_ON(dma_index >= max_entries)) + return -1; + addrs[dma_index] = addr; addr += PAGE_SIZE; - len -= PAGE_SIZE; - index++; + dma_len -= PAGE_SIZE; + dma_index++; } } return 0;