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, URIBL_BLOCKED,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 CF1D2CA90AF for ; Wed, 13 May 2020 13:27:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7676220643 for ; Wed, 13 May 2020 13:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387603AbgEMN15 (ORCPT ); Wed, 13 May 2020 09:27:57 -0400 Received: from foss.arm.com ([217.140.110.172]:46022 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728341AbgEMN15 (ORCPT ); Wed, 13 May 2020 09:27:57 -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 D01F230E; Wed, 13 May 2020 06:27:56 -0700 (PDT) Received: from [10.57.36.85] (unknown [10.57.36.85]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 101FC3F71E; Wed, 13 May 2020 06:27:54 -0700 (PDT) Subject: Re: [PATCH v4 03/38] iommu: add generic helper for mapping sgtable objects 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: Christoph Hellwig , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter , Joerg Roedel References: <20200512085710.14688-1-m.szyprowski@samsung.com> <20200512090058.14910-1-m.szyprowski@samsung.com> <20200512090058.14910-3-m.szyprowski@samsung.com> From: Robin Murphy Message-ID: Date: Wed, 13 May 2020 14:27:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200512090058.14910-3-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 2020-05-12 10:00 am, Marek Szyprowski wrote: > struct sg_table is a common structure used for describing a memory > buffer. 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 mapping functions with a wrong number of entries. > > To avoid such issues, lets introduce a common wrapper operating directly > on the struct sg_table objects, which take care of the proper use of > the nents and orig_nents entries. Modulo Joerg's comments, Reviewed-by: Robin Murphy > Signed-off-by: Marek Szyprowski > --- > For more information, see '[PATCH v4 00/38] DRM: fix struct sg_table nents > vs. orig_nents misuse' thread: > https://lore.kernel.org/dri-devel/20200512085710.14688-1-m.szyprowski@samsung.com/T/ > --- > include/linux/iommu.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 7cfd2dd..ba662ba 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -478,6 +478,22 @@ extern size_t iommu_map_sg_atomic(struct iommu_domain *domain, > extern void iommu_set_fault_handler(struct iommu_domain *domain, > iommu_fault_handler_t handler, void *token); > > +/** > + * iommu_map_sgtable - Map the given buffer to the IOMMU domain > + * @domain: The IOMMU domain to perfor > + * @iova: The start addrees to map the buffer > + * @sgt: The sg_table object describing the buffer > + * @prot: IOMMU protection bits > + * > + * Create a mapping at @iova for the buffer described by a scatterlist > + * stored in the given sg_table object in the provided IOMMU domain. > + */ > +static inline size_t iommu_map_sgtable(struct iommu_domain *domain, > + unsigned long iova, struct sg_table *sgt, int prot) > +{ > + return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot); > +} > + > extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); > extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); > extern void generic_iommu_put_resv_regions(struct device *dev, > 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, URIBL_BLOCKED,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 AF554C2D0FA for ; Wed, 13 May 2020 13:28:00 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 47FA4204EF for ; Wed, 13 May 2020 13:27:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47FA4204EF 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 whitealder.osuosl.org (Postfix) with ESMTP id 55E9087D15; Wed, 13 May 2020 13:28:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0XzZI4semBNH; Wed, 13 May 2020 13:27:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 26C8E81B88; Wed, 13 May 2020 13:27:59 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 12DD4C0178; Wed, 13 May 2020 13:27:59 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 45F72C016F for ; Wed, 13 May 2020 13:27:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 412FE86F54 for ; Wed, 13 May 2020 13:27:58 +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 HvbY6eUKMiFb for ; Wed, 13 May 2020 13:27:57 +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 fraxinus.osuosl.org (Postfix) with ESMTP id 6B893869EA for ; Wed, 13 May 2020 13:27:57 +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 D01F230E; Wed, 13 May 2020 06:27:56 -0700 (PDT) Received: from [10.57.36.85] (unknown [10.57.36.85]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 101FC3F71E; Wed, 13 May 2020 06:27:54 -0700 (PDT) Subject: Re: [PATCH v4 03/38] iommu: add generic helper for mapping sgtable objects 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: <20200512085710.14688-1-m.szyprowski@samsung.com> <20200512090058.14910-1-m.szyprowski@samsung.com> <20200512090058.14910-3-m.szyprowski@samsung.com> From: Robin Murphy Message-ID: Date: Wed, 13 May 2020 14:27:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200512090058.14910-3-m.szyprowski@samsung.com> Content-Language: en-GB Cc: Bartlomiej Zolnierkiewicz , David Airlie , Daniel Vetter , 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 2020-05-12 10:00 am, Marek Szyprowski wrote: > struct sg_table is a common structure used for describing a memory > buffer. 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 mapping functions with a wrong number of entries. > > To avoid such issues, lets introduce a common wrapper operating directly > on the struct sg_table objects, which take care of the proper use of > the nents and orig_nents entries. Modulo Joerg's comments, Reviewed-by: Robin Murphy > Signed-off-by: Marek Szyprowski > --- > For more information, see '[PATCH v4 00/38] DRM: fix struct sg_table nents > vs. orig_nents misuse' thread: > https://lore.kernel.org/dri-devel/20200512085710.14688-1-m.szyprowski@samsung.com/T/ > --- > include/linux/iommu.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 7cfd2dd..ba662ba 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -478,6 +478,22 @@ extern size_t iommu_map_sg_atomic(struct iommu_domain *domain, > extern void iommu_set_fault_handler(struct iommu_domain *domain, > iommu_fault_handler_t handler, void *token); > > +/** > + * iommu_map_sgtable - Map the given buffer to the IOMMU domain > + * @domain: The IOMMU domain to perfor > + * @iova: The start addrees to map the buffer > + * @sgt: The sg_table object describing the buffer > + * @prot: IOMMU protection bits > + * > + * Create a mapping at @iova for the buffer described by a scatterlist > + * stored in the given sg_table object in the provided IOMMU domain. > + */ > +static inline size_t iommu_map_sgtable(struct iommu_domain *domain, > + unsigned long iova, struct sg_table *sgt, int prot) > +{ > + return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot); > +} > + > extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); > extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); > extern void generic_iommu_put_resv_regions(struct device *dev, > _______________________________________________ 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,URIBL_BLOCKED,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 198FFC2D0FA for ; Wed, 13 May 2020 13:39:14 +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 EDFC4223E0 for ; Wed, 13 May 2020 13:39:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="o/iCy6GE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDFC4223E0 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=XMwuJDRIn955PY2hZZ1JJApn60/Ee4MnjvrUz8e+p7I=; b=o/iCy6GEnK+NkuUQabUxSjh+i zdxjx1tn0AUPWkDC3M2+AX9Q+/i9H7ASEIT7d4hIuG00ZWfekPkKmPVYusuk9fU8DVQdm4R8X8n23 +sFD98hs2b4Y6/hCdebg7Nl3BwxvDRxymI3SZ5yzZTeamCAD1vjol6TxPgNBGVCx16hX2izkc8Csc shVaCGFr9v2xuDGb6CD+wrAR3oPFIR6E0lqDsl1sbZuaHqK3zda0H++lyFsrqqyGHIrYwdJy+Ny3O Tbc3+X4+Rqg82RFRbJykYqWooTldG5FTB7nVzpG4Pu4zMtULeEe4JndD5nsWlM4xsX0oq8IRn8MKq bpCiFaoOQ==; 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 1jYrQY-0005WX-50; Wed, 13 May 2020 13:28:02 +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 1jYrQU-0005Va-4k for linux-arm-kernel@lists.infradead.org; Wed, 13 May 2020 13:27:59 +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 D01F230E; Wed, 13 May 2020 06:27:56 -0700 (PDT) Received: from [10.57.36.85] (unknown [10.57.36.85]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 101FC3F71E; Wed, 13 May 2020 06:27:54 -0700 (PDT) Subject: Re: [PATCH v4 03/38] iommu: add generic helper for mapping sgtable objects 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: <20200512085710.14688-1-m.szyprowski@samsung.com> <20200512090058.14910-1-m.szyprowski@samsung.com> <20200512090058.14910-3-m.szyprowski@samsung.com> From: Robin Murphy Message-ID: Date: Wed, 13 May 2020 14:27:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200512090058.14910-3-m.szyprowski@samsung.com> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200513_062758_226633_1D6387F2 X-CRM114-Status: GOOD ( 20.01 ) 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: Bartlomiej Zolnierkiewicz , David Airlie , Joerg Roedel , Daniel Vetter , 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 2020-05-12 10:00 am, Marek Szyprowski wrote: > struct sg_table is a common structure used for describing a memory > buffer. 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 mapping functions with a wrong number of entries. > > To avoid such issues, lets introduce a common wrapper operating directly > on the struct sg_table objects, which take care of the proper use of > the nents and orig_nents entries. Modulo Joerg's comments, Reviewed-by: Robin Murphy > Signed-off-by: Marek Szyprowski > --- > For more information, see '[PATCH v4 00/38] DRM: fix struct sg_table nents > vs. orig_nents misuse' thread: > https://lore.kernel.org/dri-devel/20200512085710.14688-1-m.szyprowski@samsung.com/T/ > --- > include/linux/iommu.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 7cfd2dd..ba662ba 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -478,6 +478,22 @@ extern size_t iommu_map_sg_atomic(struct iommu_domain *domain, > extern void iommu_set_fault_handler(struct iommu_domain *domain, > iommu_fault_handler_t handler, void *token); > > +/** > + * iommu_map_sgtable - Map the given buffer to the IOMMU domain > + * @domain: The IOMMU domain to perfor > + * @iova: The start addrees to map the buffer > + * @sgt: The sg_table object describing the buffer > + * @prot: IOMMU protection bits > + * > + * Create a mapping at @iova for the buffer described by a scatterlist > + * stored in the given sg_table object in the provided IOMMU domain. > + */ > +static inline size_t iommu_map_sgtable(struct iommu_domain *domain, > + unsigned long iova, struct sg_table *sgt, int prot) > +{ > + return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot); > +} > + > extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); > extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); > extern void generic_iommu_put_resv_regions(struct device *dev, > _______________________________________________ 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, URIBL_BLOCKED,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 723D3C2D0FC for ; Wed, 13 May 2020 13:27:59 +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 107FF204EF for ; Wed, 13 May 2020 13:27:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 107FF204EF 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 AF85A89D4A; Wed, 13 May 2020 13:27:58 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 3414D89D4A for ; Wed, 13 May 2020 13:27:57 +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 D01F230E; Wed, 13 May 2020 06:27:56 -0700 (PDT) Received: from [10.57.36.85] (unknown [10.57.36.85]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 101FC3F71E; Wed, 13 May 2020 06:27:54 -0700 (PDT) Subject: Re: [PATCH v4 03/38] iommu: add generic helper for mapping sgtable objects 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: <20200512085710.14688-1-m.szyprowski@samsung.com> <20200512090058.14910-1-m.szyprowski@samsung.com> <20200512090058.14910-3-m.szyprowski@samsung.com> From: Robin Murphy Message-ID: Date: Wed, 13 May 2020 14:27:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200512090058.14910-3-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: Bartlomiej Zolnierkiewicz , David Airlie , Joerg Roedel , 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 2020-05-12 10:00 am, Marek Szyprowski wrote: > struct sg_table is a common structure used for describing a memory > buffer. 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 mapping functions with a wrong number of entries. > > To avoid such issues, lets introduce a common wrapper operating directly > on the struct sg_table objects, which take care of the proper use of > the nents and orig_nents entries. Modulo Joerg's comments, Reviewed-by: Robin Murphy > Signed-off-by: Marek Szyprowski > --- > For more information, see '[PATCH v4 00/38] DRM: fix struct sg_table nents > vs. orig_nents misuse' thread: > https://lore.kernel.org/dri-devel/20200512085710.14688-1-m.szyprowski@samsung.com/T/ > --- > include/linux/iommu.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 7cfd2dd..ba662ba 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -478,6 +478,22 @@ extern size_t iommu_map_sg_atomic(struct iommu_domain *domain, > extern void iommu_set_fault_handler(struct iommu_domain *domain, > iommu_fault_handler_t handler, void *token); > > +/** > + * iommu_map_sgtable - Map the given buffer to the IOMMU domain > + * @domain: The IOMMU domain to perfor > + * @iova: The start addrees to map the buffer > + * @sgt: The sg_table object describing the buffer > + * @prot: IOMMU protection bits > + * > + * Create a mapping at @iova for the buffer described by a scatterlist > + * stored in the given sg_table object in the provided IOMMU domain. > + */ > +static inline size_t iommu_map_sgtable(struct iommu_domain *domain, > + unsigned long iova, struct sg_table *sgt, int prot) > +{ > + return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot); > +} > + > extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); > extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); > extern void generic_iommu_put_resv_regions(struct device *dev, > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel