Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751827AbcKHNwu (ORCPT ); Tue, 8 Nov 2016 08:52:50 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:12934 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751100AbcKHNws (ORCPT ); Tue, 8 Nov 2016 08:52:48 -0500 X-AuditID: cbfec7f2-f79556d000002c42-a6-5821d615fe0f Subject: Re: [PATCH] iommu/dma-iommu: properly respect configured address space size To: Robin Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Joerg Roedel From: Marek Szyprowski Message-id: <8286728f-fab3-8179-5215-e156da426244@samsung.com> Date: Tue, 08 Nov 2016 14:41:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-version: 1.0 In-reply-to: <68e7a18b-739e-b73e-eacf-3cb6c1bd279a@arm.com> Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42LZduzneV3Ra4oRBh+XaFgs2G9t0Tl7A7vF psfXWC0u75rDZnHwwxNWB1aPJwfnMXmsmbeG0WPzknqPyTeWM3p83iQXwBrFZZOSmpNZllqk b5fAlTG7cT5rwWWhis6r05gbGCfxdzFyckgImEic/fqEDcIWk7hwbz2QzcUhJLCUUeLbxOVQ zmdGidM9S1lhOu7s/QGVWMYosXnpOmYI5zmjxPFVT5lBqoQFwiQW9q9gAUmICPQzSnRNaWUC STALKEkcXXuGBcRmEzCU6HrbBTSKg4NXwE6i+y8XSJhFQFXidFMn2DZRgRiJ21Ougc3kFRCU +DH5HgtIOaeAtcTzab4QE60knv1rZYWw5SU2r3kLdo+EwHR2iZVbH7GD1EsIyEpsOsAMYbpI TJyhBfGLsMSr41vYIWwZic6Og0wQ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3tDE0NzS0MjYwsLcyEhJnLfkw5VwIYH0xJLU7NTUgtQimD4m Dk6pBkaLJNml1q+cNKcopLptv3pBgmtxi4RWm6L8QaGG/0yWIZs4FotcX7jHpk36CXdJWYqX wv+gY2FFOs9n3l7+yvaIuX+SklHkjc2xHYbxGoFdVvqqF+7eWsYZ09z9/9WjjYenKPhv/ays GvD75CfRrM/8qws9P9w4pJlof3zTaSED9+kWC3Y0iSmxFGckGmoxFxUnAgBZKrFvtgIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161108134141eucas1p2e7d9134a35009b2189dc9aadbd418ba6 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161107130625eucas1p2dd23c07010b4f3eddb6c6540ed802246 X-RootMTR: 20161107130625eucas1p2dd23c07010b4f3eddb6c6540ed802246 References: <1478523973-8828-1-git-send-email-m.szyprowski@samsung.com> <68e7a18b-739e-b73e-eacf-3cb6c1bd279a@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2335 Lines: 50 Hi Robin, On 2016-11-08 12:37, Robin Murphy wrote: > On 07/11/16 13:06, Marek Szyprowski wrote: >> When one called iommu_dma_init_domain() with size smaller than device's >> DMA mask, the alloc_iova() will not respect it and always assume that all >> IOVA addresses will be allocated from the the (base ... dev->dma_mask) range. > Is that actually a problem for anything? Yes, I found this issue while working on next version of ARM & ARM64 DMA-mapping/IOMMU integration patchset and adapting Exynos drivers for the new IOMMU/DMA-mapping glue. Some Exynos devices (codec and camera isp) operate only on the limited (and really small: 256M for example) DMA window. They use non-standard way of addressing memory: an offset from the firmware base. However they still have 32bit DMA mask, as the firmware can be located basically everywhere in the real DMA address space, but then they can access only next 256M from that firmware base. > >> This patch fixes this issue by taking the configured address space size >> parameter into account (if it is smaller than the device's dma_mask). > TBH I've been pondering ripping the size stuff out of dma-iommu, as it > all stems from me originally failing to understand what dma_32bit_pfn is > actually for. The truth is that iova_domains just don't have a size or > upper limit; however if devices with both large and small DMA masks > share a domain, then the top-down nature of the allocator means that > allocating for the less-capable devices would involve walking through > every out-of-range entry in the tree every time. Having cached32_node > based on dma_32bit_pfn just provides an optimised starting point for > searching within the smaller mask. Right, this dma_32bit_pfn was really misleading at the first glance, but then I found that this was something like end_pfn in case of dma-iommu code. > Would it hurt any of your use-cases to relax/rework the reinitialisation > checks in iommu_dma_init_domain()? Alternatively if we really do have a > case for wanting a hard upper limit, it might make more sense to add an > end_pfn to the iova_domain and handle it in the allocator itself. The proper support for end_pfn would be a better approach probably, especially if we consider readability of the code. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland