Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2021798imm; Tue, 10 Jul 2018 11:45:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcr39Ie2fQTcP9dWcQqc9XaDnor89C4t1wCALN//V1E5+weirmGOTYpl+oBr1OeacxyNG4o X-Received: by 2002:a65:5cc5:: with SMTP id b5-v6mr23515343pgt.425.1531248359864; Tue, 10 Jul 2018 11:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531248359; cv=none; d=google.com; s=arc-20160816; b=kI5EFNgrJL7Tja/4ojjATagKI7qc+zb6x2tGMjn3a/PhkpxFm4u8nu7QjIYuADBgYP bzaIV6Yw0qITMd0pEkGEkAVXbcWUF/o1sgXFUDGm1M+7kgMPvS2x/mjPae70TlCs98bY tzO6Zn1mEm5u/fOf1JimjLvq9odfvcxwIOlPOIWxun01QeNPjnCMQF/xkQVIzVMNt/I+ ZZ8ekUvbf49c5F3dW0pRrLoYGWC1dbNX1afB+J1jk/wToH1zlVr91KgozF8LfBmmVuW9 hGoJC6kbEwnIMbISO9Mr0mI5D71hItp2itK+zd9wr/6rFCO5qRzqiiTJYJuFz9NoeimM LMVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=kBeyNZcWUwwoTpUpa/J+yNJFGbjecpuLODV7TrsKCnM=; b=fTKGqyANJNB8a4/hgekBQJDWdciYZWfiu+Ka5oE2m19xB5QLikMuVbXmlP1extqOFG fX1YVBNNTG9MhU1BBziFDRZTDp7PhhkU/P6k7tMqJ3GDRwsVqFh/Ym3mCYNH0vytCCO9 Ss+ukzV2xgDjtlPRxej0fcjew/RELVUvK/LMwo2VDpJh5QO7sAWNg7E6JfF0IX1m7OXR 8pqcCpM1PUvtrJWBGeX+EZOc0ne4mpKvElNIM+vYogi3msTKQk6vhMeYxT5l8HRHIVCw pDaalbQ5aK3XkTFHBbX4neocemjTMP9fiHdqFB/7GKPn+VeHvSbWMVLjG6j82XC0tRAq 18Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s64-v6si16403665pgs.499.2018.07.10.11.45.44; Tue, 10 Jul 2018 11:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389018AbeGJSdm (ORCPT + 99 others); Tue, 10 Jul 2018 14:33:42 -0400 Received: from foss.arm.com ([217.140.101.70]:51800 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732681AbeGJSdm (ORCPT ); Tue, 10 Jul 2018 14:33:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 044811713; Tue, 10 Jul 2018 10:17:39 -0700 (PDT) Received: from e110467-lin.cambridge.arm.com (e110467-lin.cambridge.arm.com [10.1.210.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 751F63F589; Tue, 10 Jul 2018 10:17:36 -0700 (PDT) From: Robin Murphy To: hch@lst.de, m.szyprowski@samsung.com, iommu@lists.linux-foundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.pieralisi@arm.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, robh+dt@kernel.org, frowand.list@gmail.com, gregkh@linuxfoundation.org, joro@8bytes.org, x86@kernel.org Subject: [RFC PATCH 4/4] iommu/dma: Respect bus DMA limit for IOVAs Date: Tue, 10 Jul 2018 18:17:19 +0100 Message-Id: <2c0d7437ee7ccdd58da25faa283bd3c3148b961b.1531239284.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.17.1.dirty In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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_domain *domain, if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1))) iova_len = roundup_pow_of_two(iova_len); + if (dev->bus_dma_mask) + dma_limit &= dev->bus_dma_mask; + if (domain->geometry.force_aperture) dma_limit = min(dma_limit, domain->geometry.aperture_end); -- 2.17.1.dirty