From patchwork Tue Nov 4 13:57:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 5227931 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3C2049F3EE for ; Tue, 4 Nov 2014 14:00:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2144E20166 for ; Tue, 4 Nov 2014 14:00:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1DA3120138 for ; Tue, 4 Nov 2014 14:00:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XlecG-0003E7-Ce; Tue, 04 Nov 2014 13:57:48 +0000 Received: from 8bytes.org ([81.169.241.247] helo=theia.8bytes.org) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XlecD-00032Z-HU for linux-arm-kernel@lists.infradead.org; Tue, 04 Nov 2014 13:57:46 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id 44642515; Tue, 4 Nov 2014 14:57:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1415109437; bh=RtjI9Uyw8QgPsGImIyBVj0SChv9C24AdJmiFQNVZxuU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gkixeNm1hJS/Gm0IJTNoaeV+JMnBpfZJwNJ/f3cm2hyEWH6knyuzn5DiYCl3E9lwb /uQO1JMPREZUM9OOs6bNfGzUuRoStYxo6z2sdtk0nmNuOZbRM5GxEKI8sds1/S3c5O iFPqKbpTF7DFn4/QMPX08hbNQRP6z6PjCQ38W5Fm5UUo4gKeJ9C1hSzg6j7PPPyopo oBIHFjxcX71GhvNcwp9FKTEbuyNz5bf1jF80Vmmu+jrcWrIRtho/TUAg9n3xzpWt95 jPKpId3W0+5zSlHM8KGDaDvVzadVBm/SKSHRo1LyTMgmJAf7Lg7IR5BtasgnCSO9cz 9nmxj6phVVQJg== Date: Tue, 4 Nov 2014 14:57:16 +0100 From: Joerg Roedel To: Olav Haugan Subject: Re: [PATCH v6 1/1] iommu-api: Add map_sg function Message-ID: <20141104135716.GA14512@8bytes.org> References: <1414256116-26933-1-git-send-email-ohaugan@codeaurora.org> <1414256116-26933-2-git-send-email-ohaugan@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1414256116-26933-2-git-send-email-ohaugan@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141104_055745_907040_0B457E70 X-CRM114-Status: GOOD ( 18.86 ) X-Spam-Score: -0.7 (/) Cc: laurent.pinchart+renesas@ideasonboard.com, konrad.wilk@oracle.com, mitchelh@codeaurora.org, linux-arm-msm@vger.kernel.org, will.deacon@arm.com, iommu@lists.linux-foundation.org, robdclark@gmail.com, thierry.reding@gmail.com, Varun.Sethi@freescale.com, kgene.kim@samsung.com, dwmw2@infradead.org, linux-arm-kernel@lists.infradead.org, hdoyu@nvidia.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sat, Oct 25, 2014 at 09:55:16AM -0700, Olav Haugan wrote: > drivers/iommu/amd_iommu.c | 1 + > drivers/iommu/arm-smmu.c | 1 + > drivers/iommu/exynos-iommu.c | 1 + > drivers/iommu/intel-iommu.c | 1 + > drivers/iommu/iommu.c | 25 +++++++++++++++++++++++++ > drivers/iommu/ipmmu-vmsa.c | 1 + > drivers/iommu/msm_iommu.c | 1 + > drivers/iommu/omap-iommu.c | 1 + > drivers/iommu/shmobile-iommu.c | 1 + > drivers/iommu/tegra-smmu.c | 1 + > include/linux/iommu.h | 22 ++++++++++++++++++++++ > 11 files changed, 56 insertions(+) Applied to the core branch in my tree, with the patch below on-top of it. Thanks, Olav. From 38ec010d9b04ed94845f8ff6f10d33eb6bbfe180 Mon Sep 17 00:00:00 2001 From: Joerg Roedel Date: Tue, 4 Nov 2014 14:53:51 +0100 Subject: [PATCH] iommu: Do more input validation in iommu_map_sg() The IOMMU-API works on page boundarys, unlike the DMA-API which can work with sub-page buffers. The sg->offset field does not make sense on the IOMMU level, so force it to be 0. Do some error-path consolidation while at it. Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 46727ce..08c53c5 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1127,26 +1127,33 @@ EXPORT_SYMBOL_GPL(iommu_unmap); size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova, struct scatterlist *sg, unsigned int nents, int prot) { - int ret; + struct scatterlist *s; size_t mapped = 0; unsigned int i; - struct scatterlist *s; + int ret; for_each_sg(sg, s, nents, i) { phys_addr_t phys = page_to_phys(sg_page(s)); - size_t page_len = s->offset + s->length; - ret = iommu_map(domain, iova + mapped, phys, page_len, prot); - if (ret) { - /* undo mappings already done */ - iommu_unmap(domain, iova, mapped); - mapped = 0; - break; - } - mapped += page_len; + /* We are mapping on page boundarys, so offset must be 0 */ + if (s->offset) + goto out_err; + + ret = iommu_map(domain, iova + mapped, phys, s->length, prot); + if (ret) + goto out_err; + + mapped += s->length; } return mapped; + +out_err: + /* undo mappings already done */ + iommu_unmap(domain, iova, mapped); + + return 0; + } EXPORT_SYMBOL_GPL(default_iommu_map_sg);