Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3439748pxa; Tue, 25 Aug 2020 23:40:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnU8cdBOFq9QupnmT5uSmd45hhM3238qaBptLwMmRKh2W/Kib4QH9hsuW2e2Dmbh501f1M X-Received: by 2002:a17:906:fb89:: with SMTP id lr9mr10369267ejb.345.1598424039415; Tue, 25 Aug 2020 23:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598424039; cv=none; d=google.com; s=arc-20160816; b=CbdBFUog44hWSAsDL+iB87KXH90AL8nVqoLHUdu08zHe/eOaoP1k/tYVe3pgNTwuvt Eg7Jp8Awb9sorxW1b2zWI4H5sm3emJbbHyyVMauUy1pBPtVoSotIkrF90XxHM7+AWZeF bu9T+4AX/YH6181kBpnyMiGEJyOFQW3GTiK3H9WAGHIJ0drfiEmZR9cp5txNMuSqkPyu GwfQuD1A9gCVBiUgZEZf7OKF/kEaN302NW0N2HfP0g3HUSzOBEgYY1DIx5Ao8HRpvuXj FZ/i5DyJEHqWzfhXX2CTachCj4DnBUvuIuqNInxNrJrkp0wU2VTTdlY49hBRtfh2Ieei /2mA== 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:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=QOEXRl2z3ozWMJXcJ/ZYCIy/nZzMSXSHvZvf61p4Upk=; b=VNMgfRmiQuJ7ARB33zqyNUiQHBbkdXpe95K4VqDK+AHA9jdxZct3S25/QW6enNsaU8 QJGUXuiCOuCkcvuZRlvrSH3Az5/8lpZ2m2god+mGuOM6tw2YOy9mncihVmIcjiDrVnBn FgJdQ3Qc3V1yffA1Rr2SaI1eNpVHU9jalzCYrMLc2lBixBn4DsuVv/f7yov4sUzeZ5QU FgKyEq6WSg+1+AEkKY6SB8tnbq/AD8mYd/4I1dRANsmEfHiceJkBwCIzpp3Gxor7Y5X3 v2hEdap1gsdkmcz77sbLV3fRXQoUDcqyS/gJNvLIhA8dG+wwlOiCHLw42MOpx8fHS7M1 g/9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=otI7hKyr; 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 h12si941697ejt.546.2020.08.25.23.39.52; Tue, 25 Aug 2020 23:40:39 -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=otI7hKyr; 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 S1727913AbgHZGiZ (ORCPT + 99 others); Wed, 26 Aug 2020 02:38:25 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:37770 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726790AbgHZGfh (ORCPT ); Wed, 26 Aug 2020 02:35:37 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200826063532euoutp01ae2025a08c346d1287f750e2e3472865~uvep5IkOy1716617166euoutp01c for ; Wed, 26 Aug 2020 06:35:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200826063532euoutp01ae2025a08c346d1287f750e2e3472865~uvep5IkOy1716617166euoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1598423732; bh=QOEXRl2z3ozWMJXcJ/ZYCIy/nZzMSXSHvZvf61p4Upk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otI7hKyrp9QAT1M0nCbWLr+8NOuOyLyNGATXpd18lfpTWZi5aCepmg0+XsQcCTDT4 rjzEX0Eh8iMt8I0vfci8NAPF0plt7BCwMgoFRFKE9XAZsKP+U0bGwEqbFY45+zlxeY /zN/g5Zj8v8Lk92FEqR89BqeJLUhdgpt1nWq5xYI= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200826063532eucas1p1c5382498e35b316d615de0e68e361b34~uveplMohD1475914759eucas1p1c; Wed, 26 Aug 2020 06:35:32 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 4E.23.06456.4B2064F5; Wed, 26 Aug 2020 07:35:32 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200826063531eucas1p18dbb3c42b2ecc490360e7a75cf579af6~uvepRc1_b1289512895eucas1p1c; Wed, 26 Aug 2020 06:35:31 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200826063531eusmtrp2c6ddecca99882a01b52665c1a9eb88cd~uvepQuhRj0466204662eusmtrp2E; Wed, 26 Aug 2020 06:35:31 +0000 (GMT) X-AuditID: cbfec7f2-7efff70000001938-ba-5f4602b47c75 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CD.43.06017.3B2064F5; Wed, 26 Aug 2020 07:35:31 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200826063531eusmtip2f1c4e657ba9c308fbe715b9adb179fcb~uveogjcW30302303023eusmtip2v; Wed, 26 Aug 2020 06:35:30 +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 , Kukjin Kim , Krzysztof Kozlowski , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , linux-samsung-soc@vger.kernel.org Subject: [PATCH v9 07/32] drm: exynos: fix common struct sg_table related issues Date: Wed, 26 Aug 2020 08:32:51 +0200 Message-Id: <20200826063316.23486-8-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200826063316.23486-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSbUhTYRTHeXbv7u6Wi9sUfLBIGCQkqJkKT1r2Hhe/FFEfzNSmXlTUKbtq 6Yc0xV7mu5JOUTOxVr7kXMPSynJoU0SnzsJQM9HA+V46sUhr86p9+53/Of/nfzg8JCbp5zuR 0fJERiGXxUoJEd7y8ZfRTce7EHpE3y5Euf09PNSsauKjvy2FGBq2LBHoeX0XDxVNFOCo+r0f mvk6iKP8qTkMGY0aAerLmBeg1eFJHtJOfeYjU1sFgVTGdh5q7BwXoI7laT5SFZuJUxK6oaoB 0O/WqnFaW/eAoF+tfePTE9kGHv2yNo0e3ZzC6OIRNaDffEkn6DxdHaBXtAcv7bkmOh7BxEYn MwoP/xuiqJJZ3wSz/a0O/QiRDkyUEghJSHlD80wJUAIRKaGeAdhVose4YhXAso0ffK5YAfBt TSuxY/n0ZF5gYwmlBtDQQO061gcMuK1BUJ5QuaDcMjhQWQB259rZhjBKjcPK+g2+rWFPXYZl rXpgY5w6BLNU6i0WUyfgkCZ/O80Z1ms+Y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55bbKRXnJhbXJqXrpecn7uJ ERhd24793LKDsetd8CFGAQ5GJR7eBWyu8UKsiWXFlbmHGCU4mJVEeJ3Ono4T4k1JrKxKLcqP LyrNSS0+xGgKdNREZinR5Hxg5OeVxBuaGppbWBqaG5sbm1koifN2CByMERJITyxJzU5NLUgt gulj4uCUamA8/TJbhenpigjJYq8dZaFh1TN26PBVPxesZzBLVCiuum94W8pg88v37A3ruiW7 N+5TnFa96mboqxrzbW/uSH2bH3fpI8Mux8m7Os5zzT3758Hmmam3frKkP4laeFhM1zbhw3Jz EwkbneJnsx3/XZx438/DXvTiB7nPWlf2dMnsYasrsjlVmHVUiaU4I9FQi7moOBEAUhc//sQC AAA= X-CMS-MailID: 20200826063531eucas1p18dbb3c42b2ecc490360e7a75cf579af6 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200826063531eucas1p18dbb3c42b2ecc490360e7a75cf579af6 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200826063531eucas1p18dbb3c42b2ecc490360e7a75cf579af6 References: <20200826063316.23486-1-m.szyprowski@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Documentation/DMA-API-HOWTO.txt states that the dma_map_sg() function returns the number of the created entries in the DMA address space. However the subsequent calls to the dma_sync_sg_for_{device,cpu}() and dma_unmap_sg must be called with the original number of the entries passed to the dma_map_sg(). struct sg_table is a common structure used for describing a non-contiguous memory buffer, used commonly in the DRM and graphics subsystems. It consists of a scatterlist with memory pages and DMA addresses (sgl entry), as well as the number of scatterlist entries: CPU pages (orig_nents entry) and DMA mapped pages (nents entry). It turned out that it was a common mistake to misuse nents and orig_nents entries, calling DMA-mapping functions with a wrong number of entries or ignoring the number of mapped entries returned by the dma_map_sg() function. To avoid such issues, lets use a common dma-mapping wrappers operating directly on the struct sg_table objects and use scatterlist page iterators where possible. This, almost always, hides references to the nents and orig_nents entries, making the code robust, easier to follow and copy/paste safe. Signed-off-by: Marek Szyprowski Reviewed-by: Andrzej Hajda Acked-by : Inki Dae --- drivers/gpu/drm/exynos/exynos_drm_g2d.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c index 03be31427181..967a5cdc120e 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c @@ -395,8 +395,8 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d, return; out: - dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl, - g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL); + dma_unmap_sgtable(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt, + DMA_BIDIRECTIONAL, 0); pages = frame_vector_pages(g2d_userptr->vec); if (!IS_ERR(pages)) { @@ -511,10 +511,10 @@ 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)) { + ret = dma_map_sgtable(to_dma_dev(g2d->drm_dev), sgt, + DMA_BIDIRECTIONAL, 0); + if (ret) { DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n"); - ret = -ENOMEM; goto err_sg_free_table; } -- 2.17.1