From patchwork Mon May 4 12:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 213389 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=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 9E6DAC47254 for ; Mon, 4 May 2020 12:55:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 744C42075E for ; Mon, 4 May 2020 12:55:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="qAYx9kvt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgEDMzu (ORCPT ); Mon, 4 May 2020 08:55:50 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:56273 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbgEDMyQ (ORCPT ); Mon, 4 May 2020 08:54:16 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200504125413euoutp0184f86cd69bcfc7ed0fe9f43e2be673b2~L1Gvy-Fxv2809728097euoutp01B for ; Mon, 4 May 2020 12:54:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200504125413euoutp0184f86cd69bcfc7ed0fe9f43e2be673b2~L1Gvy-Fxv2809728097euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1588596853; bh=363IWIw2RDFl8Q541Ij+nYWeRz7z6H9HYij1uvd7iTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qAYx9kvt+6ePArCX0l9J0WUPsySsvyTnSuZLdkLUng6YRqn0HvT1GcES1+6hA5IkE BiuSqM+kZ0mSs4wMpfe6Ho75w6rMcd+T39fDZkg2TRJrIkxahIFQBvgJl/9UpeodPY AeFm2RD52fcUMcffJz0sdJG+CI0hMZ3QEGm9ch3Y= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200504125413eucas1p11b0cdd5b164cbf7e597e45342524d381~L1GvVlScQ1058810588eucas1p1e; Mon, 4 May 2020 12:54:13 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 94.12.60698.57010BE5; Mon, 4 May 2020 13:54:13 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200504125412eucas1p1aa394ac0f9a88fb7be0ec2359690c416~L1GvCb15M0158001580eucas1p11; Mon, 4 May 2020 12:54:12 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200504125412eusmtrp286075c03202d614fe5cfc81f1c54ad84~L1GvBz7t02826928269eusmtrp2K; Mon, 4 May 2020 12:54:12 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-46-5eb010758d16 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 16.69.08375.47010BE5; Mon, 4 May 2020 13:54:12 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200504125412eusmtip21f459a327d510b0e4be0352ca3d3e581~L1GuW_5YK0241702417eusmtip2I; Mon, 4 May 2020 12:54:12 +0000 (GMT) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter , Inki Dae , linux-samsung-soc@vger.kernel.org Subject: [PATCH v2 05/21] drm: exynos: fix sg_table nents vs. orig_nents misuse Date: Mon, 4 May 2020 14:53:43 +0200 Message-Id: <20200504125359.5678-5-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200504125359.5678-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSa0hTYRzGec85OzsuF8cp+KqhNahRkheUOqBFRR9OBGEEEYnmKQ9qbSqb s+yLIy/UampmtSxqWDhvazptmprpTJcaal7K+wXzg4qoeEktNedR+/b8f//neZ+Xl5dARSae KxEVHcfKoxmpGBdg5saV1qNKsjjUJyWfoDStTQhVojXyqA3zY5TqWpzBqfzCBoTKHM7AKN3n AGqhaxShTGM/eFRn5Suc0rbVIJThyyCfqpv9xTslpIteFwH605IOo8uXRnj08EMrQpe+S6T7 18dQ+kmPHtBVvSqcTisrAPS8yT1IcFUQGM5Ko+JZuffJMEHkUNYDPHZFeCd9uBpTgbk9amBH QNIf9javATUQECIyD8CSb/N8blgAMG1Eg3DDPID1ZXp8J9JinNmO6AHMbfuD70ZW14q3XDjp C9XT6i3tRKYA+FVjbzOh5BACZ/KeYraFI3kRZld182waIw9CXY9liwvJQFg+N4hxdR6wsLgW VQOCsCNPwBcaie0cSFr40PQheftKZ2HL2xU+px3hpLVsW++DGx/fIFwgCcDRVgOfGx4B2HlP CzhXABxoXcVtDSh5G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J+cDozSuJNzQ1NLew NDQ3Njc2s1AS5+0QOBgjJJCeWJKanZpakFoE08fEwSnVwKj1bDrby6D5tgeWPKp7fbQvtDDl 5JIf8gpphpZnFbpiXGVT2paZLs/QDrqfGbDOc7HSupd/zyT9KD1lasB2jnnjuUuh4pHrDnzZ 4pYvFBQVI3DraF+LV2Zn5IOnhZZcl59+4FlrLyT2fe2VPr245Q/L49mf39538spi8eRN5dtD g2LfrnqmsE2JpTgj0VCLuag4EQCEwSCWpgIAAA== X-CMS-MailID: 20200504125412eucas1p1aa394ac0f9a88fb7be0ec2359690c416 X-Msg-Generator: CA X-RootMTR: 20200504125412eucas1p1aa394ac0f9a88fb7be0ec2359690c416 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200504125412eucas1p1aa394ac0f9a88fb7be0ec2359690c416 References: <20200504125017.5494-1-m.szyprowski@samsung.com> <20200504125359.5678-1-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org 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 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. Adapt the code to obey those rules. Signed-off-by: Marek Szyprowski --- For more information, see '[PATCH v2 00/21] DRM: fix struct sg_table nents vs. orig_nents misuse' thread: https://lkml.org/lkml/2020/5/4/373 --- drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c index fcee33a..f995b0c 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c @@ -396,7 +396,7 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d, out: dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl, - g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL); + g2d_userptr->sgt->orig_nents, DMA_BIDIRECTIONAL); pages = frame_vector_pages(g2d_userptr->vec); if (!IS_ERR(pages)) { @@ -511,8 +511,9 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d, g2d_userptr->sgt = sgt; - if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents, - DMA_BIDIRECTIONAL)) { + sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, + sgt->orig_nents, DMA_BIDIRECTIONAL); + if (!sgt->nents) { DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n"); ret = -ENOMEM; goto err_sg_free_table;