From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr710112.outbound.protection.outlook.com ([40.107.71.112]:8317 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727450AbeIBRVU (ORCPT ); Sun, 2 Sep 2018 13:21:20 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Robin Murphy , Christoph Hellwig , Sasha Levin Subject: [PATCH AUTOSEL 4.18 095/131] iommu/dma: Respect bus DMA limit for IOVAs Date: Sun, 2 Sep 2018 13:05:03 +0000 Message-ID: <20180902064601.183036-95-alexander.levin@microsoft.com> References: <20180902064601.183036-1-alexander.levin@microsoft.com> In-Reply-To: <20180902064601.183036-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Robin Murphy [ Upstream commit 03bfdc31176cbe21e456f889ccbbf67568831149 ] Take the new bus limit into account (when present) for IOVA allocations, to accommodate those SoCs which integrate off-the-shelf IP blocks with narrower interconnects such that the link between a device output and an IOMMU input can truncate DMA addresses to even fewer bits than the native size of either block's interface would imply. Eventually it might make sense for the DMA core to apply this constraint up-front in dma_set_mask() and friends, but for now this seems like the least risky approach. Signed-off-by: Robin Murphy Acked-by: Ard Biesheuvel Acked-by: Joerg Roedel Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/iommu/dma-iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index ddcbbdb5d658..511ff9a1d6d9 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -367,6 +367,9 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_dom= ain *domain, if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1))) iova_len =3D roundup_pow_of_two(iova_len); =20 + if (dev->bus_dma_mask) + dma_limit &=3D dev->bus_dma_mask; + if (domain->geometry.force_aperture) dma_limit =3D min(dma_limit, domain->geometry.aperture_end); =20 --=20 2.17.1