From patchwork Mon May 4 12:53:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 186130 Delivered-To: patch@linaro.org Received: by 2002:a92:8d81:0:0:0:0:0 with SMTP id w1csp92980ill; Mon, 4 May 2020 05:54:27 -0700 (PDT) X-Google-Smtp-Source: APiQypJiNL+T93v4tn7204cNo+mC5OoDRON7G/5Ms7cpdjmyqy2T02XdwtH6aiRNkHJpKvvC1DQF X-Received: by 2002:a62:1a53:: with SMTP id a80mr18114531pfa.157.1588596866916; Mon, 04 May 2020 05:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588596866; cv=none; d=google.com; s=arc-20160816; b=wpmF+iQ2OEffw7KpGIZRQmxKrW8bsQtRqgVqAD1vls33MSABSHgotT+MvQ1NrmZFIz czD2kTEs+zaE2cOa0puL89IWhS5lyWDfDo6df0C0d4sYvspHKdS6YGBjWV5oQd08gavq +H8kVk7P645E4RNi3bG8SoiTKuiXw1rzThVyVuwFmVk4BxN5lk0Nk2OvEALX/b4O9pAW qsNfZEQYQYlgcy3kJKC8LluTRMHh7+FIcV7s8WJZS35XUREIPdXceCFbMrwn5enBtPlk IiTFEp5Z6b4T4V3j6u2+IgO8+Sv/JHlumcUGTSNxLYqgq0eEcBdt9+jLMM05giFXEeHb R6uw== 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:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-filter:delivered-to; bh=rEbpLcXd+bZ9d8c7RazOc/N5zIEVrrFZy1mtIrYDFj0=; b=lpKtVhOQHtI+3vKbrRMVj+ad4pakAmQzcToG4FvnezbasgySMR2maSOLrwdHT9fcXL 782of3+/JqmYPneS7QM7HyV0Wu79c5XBlz9lZ9AX5OCVnFnPuz56CF3455UtX2TPVkvv eNLAwWkhJnA8MLM/5cC1Q9w2IH21zwqv/j0wMY1izBlfLDfj1pmD7Q30Eyd+Hu259yFX M3A9AdegS7Z5yazMpoUSo2Nk7IXPSLMSMUI8bfYyhYAPMv7bVJW40xTtk+ght/+qS9Ln L7SMNWrlI0aDgguUFbzGRtSn7OKHdPOAKa/VvFf+1MRlVutOOdsK/NJcBz2Em6KluJNx k88g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b="Otjz/aru"; 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 o12si6537585pjo.60.2020.05.04.05.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 05:54:26 -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="Otjz/aru"; 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 640E0896C4; Mon, 4 May 2020 12:54:16 +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 594AE89622 for ; Mon, 4 May 2020 12:54:14 +0000 (UTC) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200504125413euoutp02367d3bc7093ca60fd8054a113401accc~L1GvQSrIj1833318333euoutp02u for ; Mon, 4 May 2020 12:54:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200504125413euoutp02367d3bc7093ca60fd8054a113401accc~L1GvQSrIj1833318333euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1588596853; bh=3AsDN+Ip+DfttKjzscLc7jI+YsnIB2JKbA1xgPMfI2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Otjz/aruMzbJosj+k+Bs7pVQbG7s+jioZpb+8mHQjI1vq6ZOBkoLpie3dsszj3qNL VRELBHAD+35iW0dTJVQgVT8S05to5AEzVxCGSFbbRQe5wR1cPF+aPfFIjj+HdI1U+P KImVFQ/6ZsleD5AH9R0qqh1S8wPGUupFb2vnsRGA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200504125412eucas1p14c9a533433ce915e288a960b880d3fd7~L1GuxxnZU0159401594eucas1p1x; Mon, 4 May 2020 12:54:12 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 53.12.60698.47010BE5; Mon, 4 May 2020 13:54:12 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200504125412eucas1p263f2029c4fd299db92b365d7b66316a0~L1GuaZfff2246922469eucas1p2c; Mon, 4 May 2020 12:54:12 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200504125412eusmtrp1b440a81df43aafbd62abc5eb12095fc8~L1GuZc1Ua2497724977eusmtrp1U; Mon, 4 May 2020 12:54:12 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-44-5eb010743d0d Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id B3.06.07950.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 20200504125411eusmtip2951048608315bac83b0939c8772239f8~L1Gtnq0EO0350103501eusmtip20; Mon, 4 May 2020 12:54:11 +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 Subject: [PATCH v2 04/21] drm: etnaviv: fix sg_table nents vs. orig_nents misuse Date: Mon, 4 May 2020 14:53:42 +0200 Message-Id: <20200504125359.5678-4-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: H4sIAAAAAAAAA0VSaUgUURzvzezsjuLmtAo+PBIXOsU7ZEjTRD9MhNGBIIHmlpOK947rFZRr Xq26mhYepZhEmkfrlZmWx5raolieaGlqlqUgJR5lm5bTqH37ne8Hfx6OiroxYzwoLIqWhklC xHxdXmP3+hurKKLG17Z13YLM7NcgZG2+CiNzXowj5J/G2yg5vPqNTzbnTwjIx5VdCFnS5kRO F22ZK8MzCPkzrxgh62ZHMXKo+T6frH41KSA7vn/CTupTVcVVgBoaHUCpl2slPOp54aSAerY2 jVFT6T0IVf/wBvV+cxalcsfKANUynsCnsjZsKWVDBaCW6/afFV7UdfanQ4KiaamNi59u4K3c 4IgHhrFTIxosAaTvUwAdHBLHYLe8CFEAXVxElAM4vyQHHFkB8HNbO48jywCObI4hO5XyibsY i0VEGYCpcmy30Zc2y2MNPmEHFYsKP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sYOThYBFQlutYbgYR5BWwknvedZITYIC+xesMB sBJOAVuJmb3qIGEhgXyJu0//sUxg5FvAyLCKUSS1tDg3PbfYSK84Mbe4NC9dLzk/dxMjMJq2 Hfu5ZQdj17vgQ4wCHIxKPLwbvq6PE2JNLCuuzD3EKMHBrCTCu6MFKMSbklhZlVqUH19UmpNa fIjRFOikicxSosn5wEjPK4k3NDU0t7A0NDc2NzazUBLn7RA4GCMkkJ5YkpqdmlqQWgTTx8TB KdXAyKd+Oj3TMXn5vKiXRxL/39b56VbempD5eh3P7f7AtKTvd77d1H85Z5rYprWr7n9+dUTZ Zeey8G3v9uVuvhSqdePzxjVVjAYG57cKz7fk0NzK17bK8ryRygmf8DULFqb9P3i+qrHus8Hc Z1W71vyS409oa+9btXHq/S2N8YtdXE1/7ZSa8yHaaZUSS3FGoqEWc1FxIgBZbF/WvAIAAA== X-CMS-MailID: 20200504125412eucas1p263f2029c4fd299db92b365d7b66316a0 X-Msg-Generator: CA X-RootMTR: 20200504125412eucas1p263f2029c4fd299db92b365d7b66316a0 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200504125412eucas1p263f2029c4fd299db92b365d7b66316a0 References: <20200504125017.5494-1-m.szyprowski@samsung.com> <20200504125359.5678-1-m.szyprowski@samsung.com> 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 , etnaviv@lists.freedesktop.org, Russell King , Robin Murphy , Christoph Hellwig , linux-arm-kernel@lists.infradead.org, Marek Szyprowski MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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/etnaviv/etnaviv_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 1.9.1 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index dc9ef30..a224a97 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -27,7 +27,8 @@ static void etnaviv_gem_scatter_map(struct etnaviv_gem_object *etnaviv_obj) * because display controller, GPU, etc. are not coherent. */ if (etnaviv_obj->flags & ETNA_BO_CACHE_MASK) - dma_map_sg(dev->dev, sgt->sgl, sgt->nents, DMA_BIDIRECTIONAL); + sgt->nents = dma_map_sg(dev->dev, sgt->sgl, sgt->orig_nents, + DMA_BIDIRECTIONAL); } static void etnaviv_gem_scatterlist_unmap(struct etnaviv_gem_object *etnaviv_obj) @@ -51,7 +52,8 @@ static void etnaviv_gem_scatterlist_unmap(struct etnaviv_gem_object *etnaviv_obj * discard those writes. */ if (etnaviv_obj->flags & ETNA_BO_CACHE_MASK) - dma_unmap_sg(dev->dev, sgt->sgl, sgt->nents, DMA_BIDIRECTIONAL); + dma_unmap_sg(dev->dev, sgt->sgl, sgt->orig_nents, + DMA_BIDIRECTIONAL); } /* called with etnaviv_obj->lock held */ @@ -405,7 +407,7 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, if (etnaviv_obj->flags & ETNA_BO_CACHED) { dma_sync_sg_for_cpu(dev->dev, etnaviv_obj->sgt->sgl, - etnaviv_obj->sgt->nents, + etnaviv_obj->sgt->orig_nents, etnaviv_op_to_dma_dir(op)); etnaviv_obj->last_cpu_prep_op = op; } @@ -422,7 +424,7 @@ int etnaviv_gem_cpu_fini(struct drm_gem_object *obj) /* fini without a prep is almost certainly a userspace error */ WARN_ON(etnaviv_obj->last_cpu_prep_op == 0); dma_sync_sg_for_device(dev->dev, etnaviv_obj->sgt->sgl, - etnaviv_obj->sgt->nents, + etnaviv_obj->sgt->orig_nents, etnaviv_op_to_dma_dir(etnaviv_obj->last_cpu_prep_op)); etnaviv_obj->last_cpu_prep_op = 0; }