Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751725AbdIAJ0N (ORCPT ); Fri, 1 Sep 2017 05:26:13 -0400 Received: from 8bytes.org ([81.169.241.247]:55100 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751457AbdIAJ0K (ORCPT ); Fri, 1 Sep 2017 05:26:10 -0400 Date: Fri, 1 Sep 2017 11:26:09 +0200 From: Joerg Roedel To: Krishna Reddy , Robin Murphy Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/dma: limit the IOVA allocated to dma-ranges region Message-ID: <20170901092609.GL19533@8bytes.org> References: <1504217301-17216-1-git-send-email-vdumpa@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1504217301-17216-1-git-send-email-vdumpa@nvidia.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1479 Lines: 40 Adding Robin for review. On Thu, Aug 31, 2017 at 03:08:21PM -0700, Krishna Reddy wrote: > Limit the IOVA allocated to dma-ranges specified for the device. > This is necessary to ensure that IOVA allocated is addressable > by device. > > Signed-off-by: Krishna Reddy > --- > drivers/iommu/dma-iommu.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 9d1cebe7f6cb..e8a8320b571b 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -364,6 +364,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, > struct iommu_dma_cookie *cookie = domain->iova_cookie; > struct iova_domain *iovad = &cookie->iovad; > unsigned long shift, iova_len, iova = 0; > + dma_addr_t dma_end_addr; > > if (cookie->type == IOMMU_DMA_MSI_COOKIE) { > cookie->msi_iova += size; > @@ -381,6 +382,10 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, > if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1))) > iova_len = roundup_pow_of_two(iova_len); > > + /* Limit IOVA allocated to device addressable dma-ranges region. */ > + dma_end_addr = (dma_addr_t)iovad->dma_32bit_pfn << shift; > + dma_limit = dma_limit > dma_end_addr ? dma_end_addr : dma_limit; This looks like a good use-case for min(). > + > if (domain->geometry.force_aperture) > dma_limit = min(dma_limit, domain->geometry.aperture_end); > > -- > 2.1.4