Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1979660ybk; Mon, 11 May 2020 08:56:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrzAVyZoqxt0D4LwIsG3dvhBY98Jg+/F3V0QLKwSZBV+UWxRzCO5SvCTow5i7Q93f0uOeT X-Received: by 2002:a05:6402:13d9:: with SMTP id a25mr6089472edx.9.1589212603979; Mon, 11 May 2020 08:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589212603; cv=none; d=google.com; s=arc-20160816; b=pMSLBftAjuUNq05PMelfaa8z1qXQN4/5pxWPWfRLzaSIA3i7JB32AGixPUEaOzDevI eMUxCSAq5sO0fVPrSJO3aipvO2KSEKikLM3TTYETs3F6eX3OXvvVpS4gg2byfX36i59L ZC/fmNEXdcVe2QKEhS4GBAQnbWEfvTrDx459Cn5Hduifg2LIQj/sxkgbvTQvpOoTFlpr s7j+/EtrwtY/tbbYLgVVtYYwzCo1kdyHk56+JKHjFkA4LIAcHSj/THb9uB9jwjd6mEjE TnQy2M3+UsfY6SA7nBvN/+FgEf1GX+xqbrwks2IwNaLX81jZgfbQyXcQmdfr9Tes0fWJ QEuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=A9aE1eQNeK+Ph+H32/SLi1YYUbGfk7luWwmGFskJorc=; b=u0RN8svVGW/qcicy7tUxlRLxi9p/vkKkPfKSNTGBj7TXWZbInEzV7Zu1eSBsAQkSiF dMjHd8ycMpAYGh3TgBatp60uhqufF6UftVzD8I5wuKEJ4m70OG5A5LS5eEn3QYq4k4SM hmx5/aQDaeDsnkgtx/2PXB/lQb2wKOK2J2cW/57YrQ27KoYz8OEABK95KbP+zc8AW/W4 GcJoJlwiGt6sN1M+1XTFhw6qJQI2MLXodTYijMYRUW5ok3/W733bvhsIpbb9320ulMZO 0NHc9qFE9Pg93ObgpznvAo9/r7sFLF4xrdVAKCJIdqqfnW/ffiQ71QJCtHhp/o6issRS h62Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si6022764ejj.84.2020.05.11.08.56.17; Mon, 11 May 2020 08:56:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730789AbgEKPv1 (ORCPT + 99 others); Mon, 11 May 2020 11:51:27 -0400 Received: from foss.arm.com ([217.140.110.172]:35120 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729556AbgEKPvZ (ORCPT ); Mon, 11 May 2020 11:51:25 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B9ED230E; Mon, 11 May 2020 08:51:24 -0700 (PDT) Received: from [192.168.1.84] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 19DA63F305; Mon, 11 May 2020 08:51:22 -0700 (PDT) Subject: Re: [PATCH v3 10/25] drm: panfrost: fix common struct sg_table related issues To: Marek Szyprowski , dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Rob Herring , Tomeu Vizoso , Bartlomiej Zolnierkiewicz , David Airlie , Daniel Vetter , Robin Murphy , Christoph Hellwig , linux-arm-kernel@lists.infradead.org References: <20200505083926.28503-1-m.szyprowski@samsung.com> <20200505084614.30424-1-m.szyprowski@samsung.com> <20200505084614.30424-10-m.szyprowski@samsung.com> From: Steven Price Message-ID: Date: Mon, 11 May 2020 16:51:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200505084614.30424-10-m.szyprowski@samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/05/2020 09:45, Marek Szyprowski wrote: > 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 the 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. A common mistake was to ignore a result > of the dma_map_sg function and don't use the sg_table->orig_nents at all. > > To avoid such issues, lets use common dma-mapping wrappers operating > directly on the struct sg_table objects and adjust references to the > nents and orig_nents respectively. > > Signed-off-by: Marek Szyprowski The change looks good to me: Reviewed-by: Steven Price Although I would have appreciated the commit message being modified to match the specifics of Panfrost - the return of dma_mpa_sg() wasn't being ignored, but the use of orig_nents/nents was indeed wrong. Steve > --- > For more information, see '[PATCH v3 00/25] DRM: fix struct sg_table nents > vs. orig_nents misuse' thread: https://lkml.org/lkml/2020/5/5/187 > --- > drivers/gpu/drm/panfrost/panfrost_gem.c | 4 ++-- > drivers/gpu/drm/panfrost/panfrost_mmu.c | 5 ++--- > 2 files changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c > index 17b654e..95d7e80 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_gem.c > +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c > @@ -41,8 +41,8 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj) > > for (i = 0; i < n_sgt; i++) { > if (bo->sgts[i].sgl) { > - dma_unmap_sg(pfdev->dev, bo->sgts[i].sgl, > - bo->sgts[i].nents, DMA_BIDIRECTIONAL); > + dma_unmap_sgtable(pfdev->dev, &bo->sgts[i], > + DMA_BIDIRECTIONAL); > sg_free_table(&bo->sgts[i]); > } > } > diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c > index ed28aeb..9926111 100644 > --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c > +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c > @@ -517,10 +517,9 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, > if (ret) > goto err_pages; > > - if (!dma_map_sg(pfdev->dev, sgt->sgl, sgt->nents, DMA_BIDIRECTIONAL)) { > - ret = -EINVAL; > + ret = dma_map_sgtable(pfdev->dev, sgt, DMA_BIDIRECTIONAL); > + if (ret) > goto err_map; > - } > > mmu_map_sg(pfdev, bomapping->mmu, addr, > IOMMU_WRITE | IOMMU_READ | IOMMU_NOEXEC, sgt); >