From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 9C335C47255 for ; Mon, 11 May 2020 15:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EBE4206DB for ; Mon, 11 May 2020 15:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730793AbgEKPv1 (ORCPT ); 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); > From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 4E464C54E8F for ; Mon, 11 May 2020 15:51:31 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 16F64206DB for ; Mon, 11 May 2020 15:51:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16F64206DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id C2F7D86D0F; Mon, 11 May 2020 15:51:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xoeS65HBAiUG; Mon, 11 May 2020 15:51:29 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1FD5D86CF8; Mon, 11 May 2020 15:51:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 08AC5C0178; Mon, 11 May 2020 15:51:29 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2644EC016F for ; Mon, 11 May 2020 15:51:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 100F5882B2 for ; Mon, 11 May 2020 15:51:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yRprP0i7ktfX for ; Mon, 11 May 2020 15:51:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by hemlock.osuosl.org (Postfix) with ESMTP id 9F9C2882B1 for ; Mon, 11 May 2020 15:51:25 +0000 (UTC) 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 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-Language: en-GB Cc: Rob Herring , Tomeu Vizoso , Bartlomiej Zolnierkiewicz , David Airlie , Daniel Vetter , Robin Murphy , Christoph Hellwig , linux-arm-kernel@lists.infradead.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" 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); > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 33AD8C47255 for ; Mon, 11 May 2020 15:51:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC7EC206DB for ; Mon, 11 May 2020 15:51:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qAvm5shh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC7EC206DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lN44T9H+XbjQMuOeLC5Cre7fYVslVDfxNb6DnEmBcyQ=; b=qAvm5shhVb5qFzVEOG3RI7eer L/8k0Q892Uo+my20YoznrFJ5s8YIXl+MQrXsizhMcCBbeVp5SOXPTATHz+u1LLDh3l8KUr9Pnx9N/ Oq5E3YWX+W6CzuxdfObMVnX7IhZ57ev5WTALRpd5Zzk3/Nj3iySmqsnxBaZBreyQ22rMJmvAh4GkM 7m1TR7advqB++vfZh8Gk7qVVEPa+ak7L7W5d2+rFcgA2ZuT4XnrzzvtSaH81IG/9ZxaMxduvSkmZl 8zQ8AdCqcFTX5ipdYOuoz7g4T85Ol+69xKA5omsJ7uFA70PnD8MisYKRTd/iHLcckMvj/ov/8PmgI DhX5eCatw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYAiJ-00036Z-LC; Mon, 11 May 2020 15:51:31 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYAiG-00035Y-Eb for linux-arm-kernel@lists.infradead.org; Mon, 11 May 2020 15:51:30 +0000 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 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-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200511_085128_578199_615D8D49 X-CRM114-Status: GOOD ( 23.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Tomeu Vizoso , Bartlomiej Zolnierkiewicz , David Airlie , Daniel Vetter , Robin Murphy , Christoph Hellwig , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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); > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham 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 116F7C54E8D for ; Mon, 11 May 2020 15:51:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9DEE206DB for ; Mon, 11 May 2020 15:51:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9DEE206DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 519376E2BD; Mon, 11 May 2020 15:51:26 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 3401A6E2BD for ; Mon, 11 May 2020 15:51:25 +0000 (UTC) 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 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-Language: en-GB 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: Tomeu Vizoso , Bartlomiej Zolnierkiewicz , David Airlie , Robin Murphy , Christoph Hellwig , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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); > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel