From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arvind Sankar Subject: Re: [PATCH 1/8] iommu/vt-d: clean up 32bit si_domain assignment Date: Sat, 21 Dec 2019 18:46:37 -0500 Message-ID: <20191221234635.GA99623@rani.riverdale.lan> References: <20191221150402.13868-1-murphyt7@tcd.ie> <20191221150402.13868-2-murphyt7@tcd.ie> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Return-path: Content-Disposition: inline In-Reply-To: <20191221150402.13868-2-murphyt7@tcd.ie> Sender: linux-kernel-owner@vger.kernel.org To: Tom Murphy Cc: iommu@lists.linux-foundation.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Lu Baolu , Andy Gross , Bjorn Andersson , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer List-Id: linux-rockchip.vger.kernel.org On Sat, Dec 21, 2019 at 03:03:53PM +0000, Tom Murphy wrote: > In the intel iommu driver devices which only support 32bit DMA can't be > direct mapped. The implementation of this is weird. Currently we assign > it a direct mapped domain and then remove the domain later and replace > it with a domain of type IOMMU_DOMAIN_IDENTITY. We should just assign it > a domain of type IOMMU_DOMAIN_IDENTITY from the begging rather than > needlessly swapping domains. > > Signed-off-by: Tom Murphy > --- > drivers/iommu/intel-iommu.c | 88 +++++++++++++------------------------ > 1 file changed, 31 insertions(+), 57 deletions(-) > > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 0c8d81f56a30..c1ea66467918 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -5640,7 +5609,12 @@ static int intel_iommu_add_device(struct device *dev) > domain = iommu_get_domain_for_dev(dev); > dmar_domain = to_dmar_domain(domain); > if (domain->type == IOMMU_DOMAIN_DMA) { > - if (device_def_domain_type(dev) == IOMMU_DOMAIN_IDENTITY) { > + /* > + * We check dma_mask >= dma_get_required_mask(dev) because > + * 32 bit DMA falls back to non-identity mapping. > + */ > + if (device_def_domain_type(dev) == IOMMU_DOMAIN_IDENTITY && > + dma_mask >= dma_get_required_mask(dev)) { > ret = iommu_request_dm_for_dev(dev); > if (ret) { > dmar_remove_one_dev_info(dev); > -- > 2.20.1 > Should this be dma_direct_get_required_mask? dma_get_required_mask may return DMA_BIT_MASK(32) -- it callbacks into intel_get_required_mask, but I'm not sure what iommu_no_mapping(dev) will do at this point?